I have activities that needs starting based on a condition. It is very similar to the login scenario. like:
- if users are not logged in, go to login activity. after correct authentication, go to a profile activity.
- if users are already logged in, go to the profile activity directly.
update: I thought about redirecting at login activity, but if users hit back button it go back to the log in activity, I don’t want this to happen.
how can this be achieved? thanks for help.
There are two ways to do it. You mentioned the first one: from the
Loginactivity launch the second activity if user is already logged in, but call thefinishmethod of the Login activity after you have started the second one. That way users won’t be able to go back to the login activity.The other one is to create a third activity, called
LauncherActivityor something like that. From that activity you decide which activity to launch. In this case you will also have to use the finish method to kill theLauncherActivity.