0

I am new to working with the Twitter4J library and am running into a bit of a problem in Android. So I currently have an activity stack like A,B,C,D. From activity D I login to twitter using twitter4J. When the twitter login redirects back to my activity, it creates a new instance of the activity on the stack. The stack becomes A,B,C,D,TwitterLogin,D. I need my application to return to the state A,B,C,D so selecting the back button will pop activity D and bring activity C to the front.

Does anyone have any suggestions on how I would achieve this?

PPierson
  • 410
  • 3
  • 18

1 Answers1

1

adding Intent.FLAG_ACTIVITY_CLEAR_TOP to the intent that you launch in order to start Activity D should do the trick. Something like this:

Intent i = new Intent(this, ActivityD.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
validcat
  • 6,158
  • 2
  • 29
  • 38
FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • Big help, thank you! I should read through android's navigation more thoroughly. – PPierson Feb 15 '13 at 03:15
  • Just wondering, in what intent did you put the flag @PPierson ? in Activity C ?? or you put the flag in the twitterlogin intent ? i am having the same issue here, my back stack gets cleared totally after i return from twitter intent. – Jav T Sep 03 '15 at 04:22