'Activity Conditional Flow

I have a movie ticket booking app. My initial activity is the login activity where there is a "continue as guest" option in case he doesn't want to sign in or register.

Then there is the details activity, where you can see the movie details, which has a button to allow the user to book the movie, BUT ONLY if he is signed in. if not, then it opens an alert dialog to register or sign in.

What I want to do is, if he is going to the Login activity from the details activity, then I want, after signing in, to return to details activity.

BUT if the user is in the Login activity when he opens the app, then he should go to the movie list activity.



Solution 1:[1]

Use sharedpreferences to save your credentials. Example :

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Activity","activityfromwhereusermoved");
editor.apply();

Note: activityfromwhereusermoved is whether directlogin or DetailsPage

and check this in LoginActivity the string value of your key Activity like :

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String name = preferences.getString("Activity", "");
if(name.equalsIgnoreCase("DetailsPage"))
{
    //intent to DetailsPage
}
else {

//intent to direct movie list..
}

check this link .. Sp!! and Sp_Dev!! for more on saredpreference

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Subhalaxmi