在显示背景时,我想运行一些操作(不使用线程)。
在我onCreate()
的活动中,我有setContentView(R.layout.splash);
当应用程序触发onStart()
时,尚未加载布局。为什么呢?
更新:LogCat给我“活动已泄露窗口”
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="@drawable/splash"
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff" />
</LinearLayout>
的onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
}
在onStart
@Override
protected void onStart() {
super.onStart();
if (CBConstants.ASSETS_MANAGER){
String progressMsg = this.getResources().getString(R.string.progress_dialog_assets_upgrading_message);
ProgressDialog progressDialog = ProgressDialog.show(this, null, progressMsg);
progressDialog.show();
try {
[...]
} catch(Exception e) {
Log.d("appcheck", ""+e);
Intent intent = new Intent(SplashScreen.this, CBWebViewActivity.class);
startActivity(intent);
}
}
else {
Thread noAssetManager = new Thread() {
public void run() {
try {
while (splashActive && ms < splashTime) {
if(!paused)
ms=ms+100;
sleep(100);
}
} catch(Exception e) {
if (LOG) Log.d("appcheck", ""+e);
}
finally {
Intent intent = new Intent(SplashScreen.this, CBWebViewActivity.class);
startActivity(intent);
}
}
};
noAssetManager.start();
}
}