简体   繁体   中英

App launches different activities

I have a Splash Activity which goes to login activity or home activity. If the signed on is set to true, and now we are in the home activity.

Press home. Goto the app icon and open again. It shows the Splash Activity -> Home Activity. Press home. In 15 secs, we close all the activities, then long press home, select the app in the list. It opens the login activity instead of going to Splash activity.

I am not sure why this is happening. Any suggestions where could I have gone wrong.

If I understand correctly your problem, you have the following hierarchy:

SplashActivity -> [LoginActivity] -> HomeActivity

Where LoginActivity is optional.

If this is correct, you can simply add this code in the onCreate() - or even better on the onResume() (so it will be called when you go back to your activity) - method of your LoginActivity class:

if (isAlreadyLogged) {
    Intent intent = new Intent(this, HomeActivity.class);
    startActivity(intent);
}

Where isAlreadyLogged is a variable that you have to retrieve, for example from the SharedPreferences of the phone.

This way, the LoginActivity will be directly skipped if the user is already logged in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM