stefan
stefan

Reputation: 1376

Don't declare main/launcher activity in manifest

In my app I start an initial setup activity on first startup.

// main activity onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

if (PreferencesUtility.firstStartup(this) ) {// helper class to access SharedPreferences
    Intent setupActivity = new Intent(this, SetupActivity.class);
    startActivity(setupActivity);

    finish();
    return;
}
...
...

}

This code is working but I think a better place for it would be in my Application class. This wouldn't require to start and finish the main activity immediately after the "initial startup" check...

Is there a way to dynamically choose the startup activity? I tried to remove the "main" and "launcher" intent filter from Manifest.xml and added the following code in my Applications onCreate

    Intent startIntent = new Intent(this, LogBookActivity.class);

    startIntent.setAction(Intent.ACTION_MAIN);
    startIntent.addCategory(Intent.CATEGORY_LAUNCHER);  


    startActivity(startIntent);

but nothing was starting up. I thought that at least my Application's onCreate would be called...

Upvotes: 0

Views: 349

Answers (1)

Carsten
Carsten

Reputation: 806

Do you really have to launch a separate activity for this? Why don't you create a fragment for those initial steps then you don't have to terminate your main activity but simply switch to this fragment.

Upvotes: 1

Related Questions