似乎我的 Android 应用程序在错误的活动上启动。
AndroidManifest.xml 中的重要部分:
“MainActivity”应该是在应用启动时启动的活动:
<activity android:name=".MainActivity" android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="AnotherActivity"
android:label="@string/app_name">
</activity>
主要活动:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//display into log that THIS activity is started
Log.d("tag", "MainActivity");
//start async task to install the database on first startup
progressDialog = ProgressDialog.show([params...]);
new InstallDatabaseTask().execute(this);
}
/**
* 1. Installs and initializes the database.
* 2. Opens another activity.
*/
private class InstallDatabaseTask extends AsyncTask {
@Override
protected Object doInBackground(Object... params) {
progressDialog.show();
//open database so it can be installed
MyOpenHelper helper = new MyOpenHelper((Context) params[0]);
helper.getWritableDatabase().close();
//dismiss progress dialog
MainActivity.this.progressDialog.dismiss();
//start another activity
Intent intent = new Intent(MainActivity.this, AnotherActivity.class);
((Context)params[0]).startActivity(intent);
return null;
}
}
另一个活动:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//just make sure this activity was started
Log.d("tag", "another activity started");
}
但日志只显示“另一个活动开始”。