如何制作一个初始屏幕并在后台运行listview进程? [英] How to make a splash screen and run listview processes at background?

查看:66
本文介绍了如何制作一个初始屏幕并在后台运行listview进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该程序从sqlite db加载数据,对其进行一些计算,然后使用带有适配器的listview进行显示.因此,该部分已准备就绪且正在运行.如果数据足够大,则计算时间可能会变长.这很重要,因为直到列表的所有元素都未准备好,我的活动才会显示.因此,我想在开始时显示一个启动屏幕,并显示它,直到MainActivity中的所有数据都未准备好为止.如果上面有一些教程或任何建议,我会很感激的.

I have an app which loads the data from sqlite db, does some calculations with it and presents it using listview with adapter. So this part is ready and is working. In case when the data is big enough the calculation time may get long. This is important because my activity won't show until all the elements of list are not ready. For this reason I would like to show a splash screen at the start and show it until all the data in MainActivity is not ready. If there is some tutorial on it or any advice I would really apperiate that.

但是,我需要添加另一个信息,该MainActivity负责显示listView是整个应用程序中的中心单元.应用启动后,用户通常会在以后重新打开此页面.因此,从sqlite db更新或创建新的listview项的方法必须在启动屏幕活动之外可用.

However, I need to add another info that this MainActivity that is responsible for showing the listView is the central unit in whole app. User will often reopen to this page later after app is launched. So the method that updates or creates the new listview items from sqlite db must be available outside of the splash screen activity.

推荐答案

 public class SplahActivity extends Activity {

        public static final int Tick = 1000;
        public static final int Complete = 5000;
        ArrayList<String> data;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash);

            data = new ArrayList<>();
            AsyncTaskRunner runner = new AsyncTaskRunner();
            String sleepTime = time.getText().toString();
            runner.execute(sleepTime);

        }

        private class AsyncTaskRunner extends AsyncTask<String, String, String> {

            private String resp;
            @Override
            protected void onPreExecute() {
                // Things to be done before execution of long running operation. For
                // example showing ProgessDialog
            }

            @Override
            protected String doInBackground(String... params) {

                // data and save it in array
               // data = Reveice data from db
                return resp;
            }
            @Override
            protected void onPostExecute(String result) {
                // execution of result of Long time consuming operation

                Intent i = new Intent(ActivityName.this,SecondScreen.class);
                startActivity(i);
            }
        }
    }

这篇关于如何制作一个初始屏幕并在后台运行listview进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆