I have an App with a Navigation Drawer design and some activities (I know working with Fragments would probably be easier here but that wasn't feasible).
When the user clicks a drawer item, the according Activity is started with FLAG_ACTIVITY_REORDER_TO_FRONT. The up button should always take the user back to the start activity A, so when the up button is pressed I also start the A activity with the same flag.
Consider the following (capital letters are the activities, trying to visualize the backstack here):
A
user starts B from the drawer
A -> B
user presses up button, brings A in front
B -> A
user presses back button finishing A going back to B
B
user presses back button again which exits the application, but imho the user should always see the start Activity A again before leaving the app.
How would / did you guys solve this?
EDIT: #Neil, with that is: If I have
A -> B
and from there via drawer go to C I have
A -> B -> C
If the user now presses the Up button and I just close C instead of bringing A to the top, the user will be back in B which would be wrong because C is (navigationwise) not under B but they are 'siblings'.
Try to make the launchMode of that Activity B to SingleTask in your manifest file like this :
android:lanchMode="singleTask"
Your activity will not be called again.
Related
I have 3 activities in my app. A is the launcher activity, when I press on a button Activity B will be started, then I have a button to start Activity A or I can press back button and I can go to A. On back press previous values retained in and on button click new values will be set on A.
When I click a button in B , A will be started, I am using REORDER TO FRONT flag and singletop as launch mode. New activity is not getting created . When I press back button on A it will transit to B and again I press back button app exits. I want to have activity A on back press on B. I cannot do anything in onBackpressed() in B as B is used in several scenarios apart from the above mentioned scenario. How to manage it.
I have nor clearly understood what you are trying to do, but you could try the up-navigation pattern (http://developer.android.com/design/patterns/navigation.html#up-vs-back).
You would have to declare in your manifest that activity A is the parent activity of B and then use NavUtils.navigateUpFromSameTask(this); in your button OnClickListener.
(NavUtils is in the support.v4 package).
I have this issue.
I have an actvity A that starts other activity B (by onclick - button).
In B I have one back button to come back to activity A. I press it.
Now that I'm in A, I press again button to go to B.
If I use android back button (I'm in B) I come back to A first and then to B.
But now, if i press android back button again, I don't go to previus activity of A or it exit from app. I come back to B !!!
How can I prevent this behavior ?
The back button of activity B should not start activity A, but close activity B with finish:
http://developer.android.com/reference/android/app/Activity.html#finish%28%29
Note that it is probably bad user interface design to have a "back" button on the interface. This official Android page says "Don't use labeled back buttons"
http://developer.android.com/design/patterns/pure-android.html
if you wish your custom back button to swap between the acivities A and B, you should simply launch intents, that will do.
I believe your problem is with the android back button. If you do not want go to the previous activity with this action, you can write in the manifest file under the <activity> tags for both A and B activities - android:noHistory="true". Doing this will exit from the app. as the activity stack was storing none of the activities, but such a requirement is quite confusing UI approach.
I'd like to kill all activities when the user hits the back button and returns to my main activity A. My App has the following 3 activities:
A -> Displays users selections before they hit search and creates activity B.
B -> Displays a list of urls's based on the users selection and creates activity C.
C -> Opens a Webview and displays the page selected by the user.
Currently, i don't call finish() after starting activity B so when the user hits the back button in activity C they can return to the list of url's and make another selection if they want.
I'd like to create a new activity A (without the users initial selections) and ensure the existing activities B and C are killed if the user hits the back button in activity B?
Any help would be appreciated.
Thanks
O.
You can return to activity A by overriding the back button handler in activity C and launching activity A with the flag FLAG_ACTIVITY_CLEAR_TOP set, or alternatively (perhaps preferably in your case), you can just set noHistory for your activity B.
You'll have to reset activity A manually in some way in this case though.
I have a problem with activities. I have a 4 activities. First is menu, second and thirth are other menus and fourth is screen with help. In every for 3 menu screens I have a button which start activity help. In help activity I have a info about application and button. I want to this button when user use it he back to last active activity. For better understanding: when I am in first menu and click help button, activity "help" is starting and when I click button "back", activity "menu1" is starting. Algorithm must be the same for other menus. Can you help me?
Normally, if you start activity Y from activity X, when activity Y finishes, the control automatically returns to activity X.
Thus, let's say you have three menu activities A, B, C and help activity D. Then, if you do A -> D, then when D finishes, you'll be back on A. If your flow is A -> B -> D, then after D finishes, you should end up back on B. Lastly, if your flow is A -> B -> C -> D, then upon finishing of D, you should come back to C. This is something Android should do for you automatically without you having to code anything special.
Or did I misunderstood your requirements?
I have an app that supports multitasking (working in the background), however I have run into problems with the android backstack.
This is what I have:
Activity A starts Activity B for result, so...
Activity A --> Activity B
If when at Activity B the user long presses the home button and switches to another application (say the browser for example) and then long presses the home button again and comes back to my app, they will be at Activity B, however the back stack at this time will look like this:
Activity A --> Internet Browser --> Activity B
So when I do finish() to send back a result from my Activity B it does not come back to my Activity A, but rather to the Internet Browser...
This is also the case if the user doesn't use long press of the home button, but also uses the home button to come back to their launcher and then uses long press home button to come back to my app. In this case the back stack is even worse:
Home Launcher --> Activity B
So when I do finish() on Activity B, the user gets back to their home screen and they can never get back to Activity A except for if they go and start the app again from their app drawer.
Is there any way to implement multitasking work in this case? Activity B needs to always return back a result to Activity A no matter what the user opened in-between these two.
OK. After long hours of research and trying various things, here's the solution to the problem. Hopefully this helps others...
The solution is pretty straight forward and simple, in AndroidManifest.xml
set android:launchMode="singleTask" for Activity A
set android:noHistory="true" for Activity B
This way Activity B will be removed from the Stack if we go to another app like the browser or exit to the home screen, so when we come back to our app we get back to Activity A.