I have an app with several activities. I enter my app, go from activity A > B > C. Go to home screen. I click the launcher icon, it resumes activity C. All good so far. However, if I repeat this, but then open 10/15 apps, and try it again, Android restarts activity A with a backstack of C, B, A. Clicking back should go home, but it resumes activity C.
I've tried singleTop and standard launch modes for the main activity. No help!
Related
There are activities A and B. Activity A is app's entry point.
I don't want to have multiple tasks with my app in the system, so I launch activity A in singleTask mode.
A starts B (B is started in standard mode).
When user presses Home button from activity B, and then starts the application again from home screen by clicking app icon, he gets to activity A. But I want him to land in activity B.
What is the proper way to do that?
I have two activities A & B. in A, i am showing a list of titles, and on clicking a title, it will open the detailed article in activity B.
I declare A as singleinstance in Manifest.
But if I declare A as single instance, and when the Activity B is opened and paused, then Activity A is not available on backstack.
I will try to explain by reproducing:
Activity A (launchMode = SingleInstance) with list of titles.
On clicking a title, Activity B opens
On clicking back button/up navigation, Acitiviy B finishes and Activity A resumes.
Again open activity B.
Press home button of device (Activity B goes to background - onPause)
Activity B is available in Recent Apps
Open app from recent apps/launcer - Activity B opens
Clicking back button/up navigation - Act B finishes, but Act A not resumed.
How can I provide better up navigation?
For my idea, you can change lauchmode of Activity A and Activity B from Singleinstance to android:launchMode="singleTop". I work fine for me. It is well said here. Let try.
When you will press the home button the activity B would call onStop() method. For a better understanding you can refer to https://developer.android.com/guide/components/tasks-and-back-stack.html
I have an app that starts with Activity A. Among other things user can go to Activity B and return with the back button.
User can start Activity A also from Activity B using a Menu. This brings Activity A to Front again.
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Problem is: Activity A should be Home Activity. Pressing back needs to always quit the application.
Currently back will go back to Activity B, then finish.
Using FLAG_ACTIVITY_CLEAR_TOP will destroy Activity B, which I do not want as the user should find the activity where he left it (e.g. scrolling position; unless android destroyed it for memory reasons).
I just want to leave the application on back pressed on Activity A. How can I do that?
Can I clear the backstack without destroying the activities?
As an alternative I could override onBackPressed in Activity A to quit the app, but how do I exit the application? Using finish() will only close current activty an bring back other open activities. Do I nees a broadcast as suggested here: Clear Activity back stack?
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 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.