2

I have following Activities(imagine Pinterest app):

WellcomeActivity with two buttons - Sign up and Log in

LogInActivity you come here from WellcomeActivity

SignUpActivity you come here from WellcomeActivity

MainActivity - you come here after you either logged in or signed up.

When user signed up or logged in I call finish() in LogInActivity or SignUpActivity and start MainActivity. But WellcomeActivity remains in the stack, so when I press Back button I'm again in WellcomeActivity.

I can't call finish() in it when I start LogInActivity or SignUpActivity, because if user decides to go back, he will exit the app.

Now, how do I design Activity transitions to have that Pinterest-like logic?

  • Good question the next days I'll face the same problem. I think that is slovable with a flag in the manifest to hide a activity from the activity stack – rekire Dec 02 '12 at 19:51
  • 1
    When you starting `MainActivity` in intent add this flag `intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);` hope it will help you – Mohsin Naeem Dec 02 '12 at 19:54
  • @MMohsinNaeem CLEAR_TASK, I guess. It's only available for API>11. –  Dec 02 '12 at 21:21
  • it is [there](http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP) since API 11 – Mohsin Naeem Dec 03 '12 at 07:12

2 Answers2

0

I have a similar application. What I did was make a Shared Preference file that had "logged in" and "sign up" as fields. When they sign up or log in, I make this value true.

In the app, when they return to the main activity, I check for onActivityResult and if they are signed up or logged in, I finish() the activity.

THis way, when they go back before log in or sign up, it doesn't close it. I hope you understand.

Sohel Mansuri
  • 564
  • 2
  • 6
  • 18
0

Refer this answer

From WelcomeActivity, instead of startActivity(), you call startActivityForResult() when starting LoginActivity or SignupActivity.Then in the onActivityResult() of WelcomeActivity,you call finish() if resultCode is 1.

Now, when login of signup is successful, you setResult(1) in the login/signup activity, which will call onActivityResult() of WelcomeActivity with resultCode as 1 and will finish() it. If login or signup fails, you call setResult(0).

Also After setResult(1), you startActivity() to invoke MainActivity.

Community
  • 1
  • 1
Kiran Kumar
  • 1,192
  • 8
  • 10