John of Ardeal John of Ardeal - 4 months ago 8x
Android Question

Choose starting Activity

How can I dynamically select the starting Activity of my application?

Take for example this scenario: the first time the user opens the app, he will see the AuthenticationActivity, after that, he will see the MainActivity. If he logs out, he will see the AuthenticationActivity again.

I don't want to use a splash screen or something similar and I'm wondering if there is any way of doing this.

I was thinking of checking if there are any accounts in the onCreate method of the MainActivity, before calling setContentView, and display the AuthenticationActivity if not, but it doesn't feel ok to me.


You could do something like this:

public class NavigatorActivity extends Activity {
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);

        Intent intent;

        if(isAuthenticated) {
            intent = new Intent(NavigatorActivity.this, MainActivity.class);
        } else {
            intent = new Intent(NavigatorActivity.this, AuthenticationActivity.class);


And launch your app with this NavigatorActivity.