How run two AsyncTasks in one Activity?

前端 未结 4 470
名媛妹妹
名媛妹妹 2020-12-31 20:04

I have two Activitys (mainActivity & downloadActivity) and I have 2 AsyncTasks in downloadActivity

4条回答
  •  天命终不由人
    2020-12-31 20:45

    Make one class task like:

    Declare progress bar globally in main thread.

    Now what you have to do is start one async task in main thread like:

    public class myactivity extends Activity {
        private ProgressDialog _dialog;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.base_screen);
            new abc().execute();
        }
    
        class abc extends AsyncTask(String,String,String) {
            @Override
            protected void onPreExecute() {
                _dialog = new ProgressDialog(_ctx);
                _dialog.setCancelable(false);
                _dialog.setMessage("Loading");
                _dialog.show();
                super.onPreExecute();
            }
    
            @Override
            protected String doInBackground(String... params) {
                @Override
                protected void onPostExecute(String result) {
                    // in post execute of this class you can run a new thread of your downaloder thread. and in post execute of last thread you have to dismiss the progess bar.
                    new download activity.execute();
                    }
                } 
            }
        }
    }
    

提交回复
热议问题