Activity Conditional Flow

47 views Asked by At

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.

1

There are 1 answers

0
Subhalaxmi On

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