1

Here's my scenario - the app starts with an Activity A which is the main launching point. There are various other activity that are launched from A, say B & C. Going from A to B should be reversible (pressing back actually returning), so every I need A on the activity stack, same for A => C and back. All that works just fine by default.

Now here's where it gets tricky: I have another activity, say X, which can be launched from a background process (broadcast receiver). When X is launched, it should replace whatever is currently on the screen - that part is no problem. X can then either be dismissed by the user (which ends with finish() and startActivity(A) - so I don't have X on the stack). And it can also be finished by the background process (broadcast receiver receiving another intent) - and it is in the latter case where I have a problem.

I still call finish() on X and now the following happens: Whichever Activity was previously active (say A), will show again. That is fine if A showed before X launched, however, if my app was in the background, once X is dismissed I want the state prior to launching X restored (so either show the home screen, or show whichever app was running before X was launched). If you're wondering.. why am I interrupting the user - it's for a good reason (it's a telephony app and incoming calls should interrupt).

It seems to be that when I call dismiss on X, the app will return to whatever else is in the activity stack. That is fine if the app was in the foreground when X was launched, but if it wasn't, I want X to be dismissed and whichever app was active to be on top again.

Here are the intent flags I'm using when launching X: FLAG_ACTIVITY_NEW_TASK FLAG_ACTIVITY_CLEAR_TOP FLAG_ACTIVITY_NEW_TASK

I've already tried FLAG_ACTIVITY_MULTIPLE_TASK but the results were less than satisfactory (if my app was running in the background, this prevents it from coming on top when X is dismissed without user intervention, but then in the app history, it'll show X and X should never ever be shown there, plus if the user actually selects it, sure enough it launches X, and that's bad.

So briefly

Phone is in Status S1 X is launched X is dismissed without user interaction by calling finish() Phone should return to Status S1

Can this be achieved somehow?

Stephan Steiner
  • 1,043
  • 1
  • 9
  • 22
  • Activity doesn't have a dismiss method - shouldn't you just call finish() to end the activity? – Clyde Jan 25 '13 at 13:14
  • what you are getting when your X got dismissed withaout user intervention ? – kaushal trivedi Jan 25 '13 at 13:45
  • @Clyde: of course - I forgot to edit the question. Don't know how I got to dismiss. – Stephan Steiner Jan 25 '13 at 18:45
  • @kaushal trivedi: When I call finish() on X without user intervention, if my app was already running with A being the last activity the user saw (and now the app is in the background, say browser is running), after having called finish(), the user will see my app with activity A (and if B was the last activity, user will see B, etc). But the point is user should see the browser again when the browser was the last thing he saw prior to me showing X. – Stephan Steiner Jan 25 '13 at 18:47

1 Answers1

0

Try to use the flag FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS:

If set, the new activity is not kept in the list of recently launched activities.

rekire
  • 47,260
  • 30
  • 167
  • 264