0

And again about Android activities back stack magic. So I have two activities A→B (playlist A and player B), and I want the app should always close when Back pressed in A. But it doesn't.

Both activities launches as singleTop, B also has android:excludeFromRecents="true" and defined A as parent. B goes back to A with following flags Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK.

Everything works fine except the next case: A→B, Home pressed, Launch app again from desk and got A opened, Press Back button, Here app should be closed but B shown again.

Any suggestions? Thanks!

Konstantin Konopko
  • 5,229
  • 4
  • 36
  • 62
  • `and I want the app should always close when Back pressed in A. But it doesn't` When you press back and activity A is your root activity declared with launcher and inten action.main for example, and you are at activity A at the moment you press back. Then you will come back to the homescreen.. `Press Back button, Here app should be closed but B shown again.` i don't get that you want to launch directly to activity B and close A ? What do you mean with close..finish() or completely killin the task? – Mike Dec 03 '14 at 00:42
  • @Mike I want A goes to homescreen by Back pressed, but B opened (kept in stack) – Konstantin Konopko Dec 03 '14 at 00:50
  • 1
    Did you originally launch the app from the HOME screen? or from an IDE (Eclipse, etc.) or the installer? You may be seeing this: http://stackoverflow.com/a/16447508/769265 – David Wasser Dec 03 '14 at 11:34

1 Answers1

0

When you are using the Intent.FLAG_ACTIVITY_NEW_TASK , it means a new instance of the activity is launched. You may have to use Intent.FLAG_ACTIVITY_SINGLE_TOP flag with single task option in manifest.

rana
  • 1,824
  • 3
  • 21
  • 36