How can I configure Launcher activity programmatically in android?

后端 未结 6 791
忘掉有多难
忘掉有多难 2020-11-30 09:56

I am working on an app with two activities : LoginActivity and MainActivity. When the user first opens the app he will login and his credentials (u

6条回答
  •  青春惊慌失措
    2020-11-30 10:32

    Long story short, you cannot change the Activity that is launched by default. Update: There is an alternative as described by CommonsWare in another answer.

    However, there are reasonable work arounds. In your MainActivity you can check whether the user is logged in and immediately redirect them to the LoginActivity. That has the added benefit of automatically returning to the MainActivity after you have logged in.

    Alternatively, you can always go first to the LoginActivity, and if the user is already logged in, send them to the MainActivity (rewrite the Intent history to remove the return to LoginActivity or set the noHistory flag in the manifest).

提交回复
热议问题