我不知道如何分辨问题。
我有两个AsyncTask方法。 doAreYouStanding和StartTimeout,当我同时在MainActivity中运行时
如果StartTimeout在等待10秒时,则其他方法正在等待。
为什么此startTimeout线程暂停了我的其他方法?
在onPreExecute上等待10秒钟后,doInreground中的doAreYouStanding起作用了>>
new doPopup().execute((Void) null); // new StartTimeout().execute((Void) null); private class doAreYouStanding extends AsyncTask<Object, Object, Void> { @Override protected void onPreExecute() { Log.e("YHACKUP", "onPreExecute"); super.onPreExecute(); } @Override protected Void doInBackground(Object... objects) { Log.e("YHACKUP", "doInBackground"); return null; } } private class StartTimeout extends AsyncTask<Object, Object, Void> { @Override protected void onPostExecute(Void aVoid) { if (!(ActivitySplash.this).isFinishing()) { layout_timeout.setVisibility(View.VISIBLE); } super.onPostExecute(aVoid); } @Override protected Void doInBackground(Object... objects) { // try { // Thread.sleep(10000); // } catch (Exception e) { // } return null; } }
如果我的英语不好,我很抱歉
我不知道如何分辨问题。我有两个AsyncTask方法。 doAreYouStanding和StartTimeout,当我在MainActivity中同时运行时(如果我等待10秒,如果StartTimeout在中),则另一种方法...
默认情况下,异步任务以串行方式运行。因此Intil,第一个asyncTask完成,第二个asyntask将不会启动。为了轻松运行,请使用executeOnExecutor方法