Properly skip login activity if already logged in

后端 未结 5 1348
终归单人心
终归单人心 2021-01-31 03:55

My launcher icon currently starts the login activity. I\'ve stored the logged in status in SharedPreferences. Is there any way to properly skip the login activi

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 04:11

    Have a launcher acitivy with no UI that decides to open the MainActivity or the LoginActivity. You can declare no UI with:

    android:theme="@android:style/Theme.NoDisplay"
    

    Two other possible solutions:

    Just do it the other way around: make your mainActivity your launcher and make it check whether the user is logged in. Then redirect to the loginActivity when this is not the case.

    Another way is to work with fragments. Have a base activity that can load both the mainFragment and the loginFragment. For reference: https://developer.android.com/training/basics/fragments/index.html

提交回复
热议问题