14

Is there a way I can change the activity that is launched when the application is started?

user1613103
  • 175
  • 3
  • 9
  • Maybe just have a dispatcher activity that picks the target activity in `onCreate`? – nneonneo Oct 07 '12 at 00:50
  • possible duplicate of [Define Default Activity (when app starts) programmatically](http://stackoverflow.com/questions/6497725/define-default-activity-when-app-starts-programmatically) – Slava Fomin II Mar 06 '15 at 09:29

1 Answers1

19

I would recommend having a helper activity that is always designated as the launcher activity in your manifest. Then, in the onCreate of that activity you can do whatever determination you need to decide what app to start and then finish the helper activity. Example:

In your manifest (launcher activity):

<activity android:name=".HelperActivity" ... />

Then, in HelperActivity's onCreate:

@Override
public void onCreate(Bundle b){
    super.onCreate();
    //determine what activity you want
    startActivity(new Intent(this, NewActivity.class);
    finish();
}
dennisdrew
  • 4,399
  • 1
  • 25
  • 25
  • 7
    You could probably call Activity.overridePendingTransition() with 0 for the animation ID in onCreate(), then also override finish(), call Activity.overridePendingTransition(), then call super.finish(). – dennisdrew Jan 21 '14 at 21:21
  • 4
    To avoid animations and history of stack navigation I use just 'android:noHistory="true"' property in AndroidManifest. – Eugene Biryukov Jul 13 '15 at 10:38