views:

59

answers:

2

In my application I have several activities, the main screen has 4 buttons that each start a different activity. So one of them is a search activity, once it searches it shows you a result activity. This result activity can be reached from other activities, so in general something like this:

Main activity -> Search activity -> Result activity

Main acitivty -> someother activity -> Result activity

Now, if I have reached this result activity and press back once or twice, and after that press the Home key it will show the Home screen. But if I want to get back to my application by holding the Home button and clicking on my app it will always go back to the Result activity, no matter which activity was the last one I was using. And if I press again back it will take me back to the Home screen.

If I try it again it will take me again to the Result activity. The only way to avoid this is to start the application by clicking on the app's icon. And this takes me to the last activity I was using and it remembers the state so if I press back again it doesn't take me to the Home screen, instead to the activity before it. To illustrate this:

Main activity -> Search activity -> result activity --back--> Search activity --Home Button--> Home Screen --Hold Home and select the app --> Result activity --back--> Home Screen

--Click application icon--> Search activity --back--> Main activity

Another thing that happens is that if I press the Home button while on the Result activity, and start the app by clicking the icon, it will take me to the activity prior the the Result one.

Why is this happening? Any workarounds?

A: 

Set alwaysRetainTaskState to true.

BrennaSoft
Doesn't that do the *opposite* of what's desired? Plus the documentation says "this attribute is meaningful only for the root activity of a task; it's ignored for all other activities."
Christopher
I tried it anyway but the same thing happens.
janfsd
+2  A: 

It looks as though your intent.addFlags uses your own "custom" flag to send a value to your new activity (R.id.flag_search)? I'm not sure that is supported or the intended use of flags and activities. The flags are documented here:

http://developer.android.com/intl/de/reference/android/content/Intent.html#setFlags%28int%29

mikeplate
Thanks! This was the issue. I guess I have to use another method to differentiate my activities. So the only way I can think of would be by using Intent.putExtra, or is there another way?
janfsd
I do believe that Intent.putExtra is the way to go for all data sending needs between activities. Good luck!
mikeplate