更新时间:2023-01-25 17:33:52
总之,您不能更改默认启动的Activity
.更新: CommonsWare 在另一个答案中有描述.
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.
但是,有合理的解决方法.在您的MainActivity
中,您可以检查用户是否登录,并立即将他们重定向到LoginActivity
.登录后具有自动返回MainActivity
的额外好处.
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.
或者,您始终可以先进入LoginActivity
,如果用户已经登录,则将其发送到MainActivity
(重写Intent历史记录以删除对LoginActivity
的返回或设置 noHistory 标志).
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).