我創建了一個完美的啓動畫面。現在我想要在顯示啓動畫面的同時加載數據庫,並且在數據庫加載完後顯示應用程序UI。
我有下面的代碼來做到這一點是正確的?
如何在初始化數據庫時顯示啓動畫面?
public class Splash extends Activity{
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
new LoadDatabase().execute();
}
@Override
protected void onPause() {
super.onPause();
finish();
}
// Load DB
protected class LoadDatabase extends AsyncTask<Context, Integer, String>
{
@Override
protected String doInBackground(Context... params) {
try {
new DatabaseHelper(getApplicationContext()).initializeDatabase();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
@Override
protected void onPreExecute() {
super.onPreExecute();
setContentView(R.layout.splash);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Intent openMain = new Intent("com.nepways.MAIN");
startActivity(openMain);
}
}
}
有沒有什麼好的例子或建議?這個你能幫我嗎。
我發現教程UI THRE廣告和背景[處理](http://www.vogella.de/articles/AndroidPerformance/article.html#overview_intro)。 並且是指該[答案](http://stackoverflow.com/questions/1979524/android-splashscreen/1982002#1982002)。 – Uttam