Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does android:noHistory="true" work?

Tags:

android

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.

like image 713
M Jesse Avatar asked Aug 06 '12 21:08

M Jesse


People also ask

What is the use of activity tag?

activity is the subelement of application and represents an activity that must be defined in the AndroidManifest. xml file. It has many attributes such as label, name, theme, launchMode etc. android:label represents a label i.e. displayed on the screen.

What is android label?

The android:label is to define your app name, which is display in the installed application list. If you want to change the app name in home screen, check android:label inside the <activity /> tag.

How do I delete activity from Stack?

The easiest way is to give the LoginActivity a “android:noHistory = true” attribute in the manifest file. That instructs Android to remove the given activity from the history stack thereby avoiding the aforementioned behavior altogether.


2 Answers

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.

like image 62
slayton Avatar answered Oct 23 '22 23:10

slayton


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).

like image 6
Raghav Bhatia Avatar answered Oct 24 '22 00:10

Raghav Bhatia