0

I have one Splash Activity , login Activity and dashboard.

Splash Activity do GCM etc work. Login will have login only.

Now if I login and move to dashboard, when user press back button on dashboard it should redirect user to exit, Not on Login screen. Similarly if user session expired then App redirect user to login screen.

Now I handled Backbutton on Login screen, So it should not allow user to go back to prev activity, But How do I allow user to exit.

Similarly I handled Backbutton on dashboard , so it will not allow user to go to prev login screen.

  1. splash => login => dashboard
  2. Splash => dashboard (if session is not expired)
  3. dashboard=> other activity => login

What is the best way to exit from dashboard and login activity without moving to previous activity.

Ashish Kasma
  • 3,594
  • 7
  • 26
  • 29
  • 1
    You should be able to achieve this by calling `finish()` on the activity that you don't want in the stack right after starting the next activity. – Aleks G Oct 17 '13 at 12:29
  • The only way is to finish the last activity on the stack. Maybe you can us startactivityforresult. #see http://stackoverflow.com/questions/10407159/android-how-to-manage-start-activity-for-result – An-droid Oct 17 '13 at 12:30

2 Answers2

2

You can finish the activity or also you can declare the activity on the AndroidManifest.xml to don't stay on the activity stack with. Android docs

android:noHistory=["true" | "false"] 
Juangcg
  • 1,038
  • 9
  • 14
1

when user press back button on dashboard it should redirect user to exit, Not on Login screen.

For this , You should have finished activity after passing intent to Home screen like this

startActivity(new Intent(ActivityLogin.this, ActivityHome.class));
            finish();

if session get expired , Start Login activity again by passing an intent.

 startActivity(new Intent(ActivityHome.this, ActivityLogin.class));
finish();

You must use finish() each time in this scenario, In this way only a single instance of activity will be there in stack.

Jitender Dev
  • 6,907
  • 2
  • 24
  • 35