【发布时间】:2019-11-04 18:10:17
【问题描述】:
我有一个 SplashScreen Activity,它调用 Asynctask 类来获取互联网信息。
我想等待我的 Asynctask 未完成(互联网速度连接期间的时间)
我的活动:
public static boolean test = true;
[...]
final Liste en_ce_moment = new Liste("En ce moment au cinéma", nowMovie);
mesListes.add(en_ce_moment);
//call my Asynctask file
fetchNowMovie process = new fetchNowMovie();
process.execute();
while(test)
{
}
Intent i = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(i);
我的异步任务:
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
SplashScreenActivity.test = false;
SplashScreenActivity.nowMovie.clear();
SplashScreenActivity.nowMovie.addAll(list);
}
逻辑上,onPostExecute 中的布尔值变为 false,因此 while 循环停止并且意图必须启动,但 while 循环永远不会停止...
【问题讨论】:
-
嗯,
test设置为 true,所以你有while(true) { }。你期待什么? :| -
也许时间过得太快了,试着在那里睡一会儿
-
我尝试将
SystemClock.sleep(1000);放入while 循环,但@RicardoA 没有任何改变。 -
I want to wait while my Asynctask is not finish (time during on internet speed connection)如果不是异步的,为什么还要异步执行?你这样做是错的。如果您真的想要这样做,请检查任务的状态。见developer.android.com/reference/android/os/… -
@jmart SplashScreenActivity 是应用程序中第一个午餐的活动,它调用我的 asynctask,然后启动 MainActivity。我的问题代码在 SplashScreenActivity
标签: java android loops android-asynctask splash-screen