It seems like my Android app starts on the wrong activity.
The important part from AndroidManifest.xml:
“MainActivity” should be the activity that is started on app launch:
<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>
MainActivity:
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;
}
}
AnotherActivity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//just make sure this activity was started
Log.d("tag", "another activity started");
}
But the log only displays “another activity started”.
From your code i understood that android is launching the correct activity.
But in your oncreate method you are calling async task so as soon as main activity creates it launches async task and in your async task you are calling below lines
so as soon as async task do its task it launches another activity. so you are assuming that android is launching wrong activity. But internally you are launching the activity and in your your async is completed in just few micro seconds so you are assuming that wrong activity is launched..