Android 启动屏幕执行异步任务时显示空白白色屏幕
我有一个对基金交易所进行评级的应用程序,并将其显示在回收视图中。Android 启动屏幕执行异步任务时显示空白白色屏幕,android,asynchronous,android-asynctask,Android,Asynchronous,Android Asynctask,我有一个对基金交易所进行评级的应用程序,并将其显示在回收视图中。 在我对主题进行简单更改之前,我的应用程序运行良好。 我将它从@android:style/Theme.AppCompat.Light.NoActionBar“ 到android:style/Theme.NoTItleBar.Fullscreen因为我想在启动时加载应用程序时隐藏状态栏 显示 更新2 解决了这个问题。我用了一个Timertask,这很有效 protected void onPostExecute(Long tim
在我对主题进行简单更改之前,我的应用程序运行良好。 我将它从
@android:style/Theme.AppCompat.Light.NoActionBar“
到android:style/Theme.NoTItleBar.Fullscreen
因为我想在启动时加载应用程序时隐藏状态栏
显示
更新2 解决了这个问题。我用了一个Timertask,这很有效
protected void onPostExecute(Long time) {
final Intent i = new Intent(Splash.this, MainActivity.class);
handler = new Handler();
timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
startActivity(i);
finish();
}
});
}
};
if (SPLASH_DISPLAY_LENGHT - time > 0)
timer.schedule(timerTask, SPLASH_DISPLAY_LENGHT - time);
else
timer.schedule(timerTask, 5000);
}
这个解决方案对我有效 为了快速打开应用程序,我们需要禁用即时运行。。。 API 23(棉花糖)及更高版本会出现这种情况 请按照以下步骤进行相同操作: 文件->设置->构建、执行、部署->即时运行
禁用所有四个选项您的启动屏幕只是加载到apk文件中的静态图像的简单视图吗?是的。我在初始活动布局中将静态图像设置为背景。我可以看到您的初始活动布局吗?是的,当然,我会更新我的帖子。很抱歉回复太晚!@JoshFischer我解决了问题。我更改了PostExecute执行Timertask而不是synchronized(此)
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 5000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.initial_activity);
new InitialViewLoad().execute();
}
private class InitialViewLoad extends AsyncTask<Void, Void, Long> {
@Override
protected Long doInBackground(Void ... params) {
long before = System.currentTimeMillis();
List<Fund> funds = FundPortfolio.get(getApplicationContext()).getFunds();
new PricesFetcher().fetchItems(funds);
for (Fund fund : funds) {
new FinanceFetcher().fetchItems(fund);
FundPortfolio.get(getApplicationContext()).updateFund(fund);
}
long after = System.currentTimeMillis();
long time = after - before;
return time;
}
@Override
protected void onPostExecute(Long time) {
Intent i = new Intent(Splash.this, MainActivity.class);
synchronized (this) {
try {
if (SPLASH_DISPLAY_LENGHT - time > 0) {
wait(SPLASH_DISPLAY_LENGHT - time);
}
} catch (InterruptedException ioe) {
Log.e("Blah,Blah,Blah", "Blah", ioe);
} finally {
startActivity(i);
finish();
}
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#1b5e20"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@drawable/logo"
android:layout_gravity="center"/>
</LinearLayout>
protected void onPostExecute(Long time) {
final Intent i = new Intent(Splash.this, MainActivity.class);
handler = new Handler();
timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
startActivity(i);
finish();
}
});
}
};
if (SPLASH_DISPLAY_LENGHT - time > 0)
timer.schedule(timerTask, SPLASH_DISPLAY_LENGHT - time);
else
timer.schedule(timerTask, 5000);
}