我愿意做一个启动活动,我在其中收取所有数据库的内容。发生在我身上的是,活动加载布局需要大约两秒钟,这真的很难看(它显示白色布局)。
这是代码:
public class LauncherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Crashlytics.start(this);
setContentView(R.layout.activity_launcher);
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB){
getActionBar().hide();
}
Void params = null;
Tracker tracker = GoogleAnalytics.getInstance(this).getTracker("UA-44871768-1");
tracker.set(Fields.SCREEN_NAME, "Home Screen");
// Send a screen view for "Home Screen"
tracker.send(MapBuilder
.createAppView()
.build()
);
// Clear the screen name field when we're done.
tracker.set(Fields.SCREEN_NAME, null);
new LoadDBAsyncTask().execute(params);
}
private class LoadDBAsyncTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
// TODO Auto-generated method stub
// Set screen name on the tracker to be sent with all hits.
Constants.createDB(getApplicationContext());
return true;
}
@Override
protected void onPostExecute(Boolean result) {
if(result){
Intent intent = new Intent(LauncherActivity.this, QuickGameActivity.class);
startActivity(intent);
}
}
}
这是我膨胀的布局
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".QuickGameActivity"
android:background="@drawable/launcher_activity"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:scaleType="fitXY" >
</RelativeLayout>