How do these two attributes relate? If I have android:noHistory="true", does having android:finishOnTaskLaunch="true" have any significance/meaning?
Let's say you have three activities in your app: A, B, and C.
You start your app and see A, click a button and see B, click a button and see C.
First scenario
Now if you press the Back button on your phone, you will see B.
Second scenario
Let's say that B has android:noHistory="true".
Now if you press the Back button on your phone, you will see A. The android:noHistory="true" attribute removed B from the history (i.e. the activity stack), so you will not see it when you hit the Back button.
Third scenario
Let's say that C has android:finishOnTaskLaunch="true".
Now if you press the Home button on your phone and then launch the app again, you will see B. Android ended C when you launched the app again because it has the android:finishOnTaskLaunch="true" attribute.
finishOnTaskLaunch would kill the Activity as you move to another task. But noHistory would kill the Activity if you move to another activity in the same task.
Related
I have Activity A, B and C
C is launched from notification.
But, backstack gets cleared when launched from notifications. I know about TaskStackBuilder and specifying the back intents, but that will be a hardcoded back stack.
If C is launched after A, then back press should go back to A
If C is launched after A>B, then back press should go back to B and then got back to A on second back press.
How do I preserve the current back stack and add on top of it?
Set all the possible target activities' launchMode in your Manifest.xml to either "singleTop" or "singleTask" depending of your need:
<activity
android:name=".YourActivity"
android:launchMode="singleTop">
The different launch modes are well explained here.
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'm following the next flow, Start activity A (loading resources), then go to Activity B (login). I marked Activity A as noHistory = "true" and just after I start the activity B I call finish() on activity A.
The app works as expected and when I pressed the back button from the Activity B the app closes, when I pressed the recents button and select my app, it restarts from activity A, I want it to starts from activity B.
thanks.
Add this to your activity declaration in the AndroidManifest:
android:excludeFromRecents="true"
And it will be excluded from the "recent apps" list
that is expected behaviour . Since you have pressed the back button the app is closed , if you launch from recent after that its like clicking on app icon to launch the app . You can use shared preferences to save if the first activity is already launched you can directly launch second activity
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.
Lets say I have a base activity with a menu, when I click on menu item A, it goes to activity A. I open the menu again, and go to B. From B I go back to A, and back and fourth like this for a while.
So the stack would be A, B, A, B, A, B, ....
And when I hit the back button, it goes backwards through the stack as expected.
However lets say I don't want this functionality, so I add to my manifest, android:noHistory="true". So when I hit the back button it exits the application instead of going though the stack.
Now the illusion makes it seem, lets say if I'm in activity A, I use the menu and go to activity B, the stack would just be B, because I can't go back to A.
But, when using noHistory="true", does the true stack of A, B, A, B, A, B exist? Rather, is every call to an activity by using the menu instantiating a new copy of that activity, but the user can't see it? Would this be causing resource issues?
Or when noHistory="false", does the back button just call something like startAcitvity(intent) again or is it going through each new copy that was instantiated?
I'm concerned with resource issues and not slowing down a users android device.
From the docs about noHistory:
A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it.
Regarding your question:
does the true stack of A, B, A, B, A, B exist?
The docs would indicate no.
I'm concerned with resource issues and not slowing down a users android device.
You really don't need to worry about this. The OS should handle the cleanup of activities when memory is getting low. Its more likely that poor use of bitmaps or logic in your activities will result in performance slowdowns.
android:noHistory=“true” works :-
Let suppose you have opened "your app".
You are on homepage Activity now,
After it you go to the another(second) activity.Here from second activity you press the home button of mobile device or open the some other application.
Now again if you open "your app" it will go to the homepage of app instead of going to the activity which one you left the app(i.e.second activity).
I had few fragments in my app and it seemed difficult to get out to the home screen by pressing back button without entering Launcher Activity of my app. I used android:noHistory="true" in the manifest of the launcher Activity of my app and the problem gets solved now.