I am using following code to open an activity as a popup window using
<activity android:name=".RadioButtonExample"
android:theme="#android:style/Theme.Dialog"
android:excludeFromRecents="true"/>
But excludeFromRecents is not working. If user clicks back button the popup window shows while retrieving back to main menu.
Use android:noHistory="true"
Whether or not the activity should be removed from the activity stack
and finished (its finish() method called) when the user navigates away
from it and it's no longer visible on screen — "true" if it should be
finished, and "false" if not. The default value is "false". 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.
Related
i have custom activity which is called from background by receiver.
After on button click i want to close activity, so cannot be opened again if user holds menu button and list of active apps is displayed.
How can i do it? I tried use finish() method and kill process, but without luck..i can always display activity from list of apps again.
Thanks for any help.
Edit:
I Just added
<activity android:noHistory="true"
But after finish the activity i am able to get back into the activity (See image below).
Activity is started from receiver with following flags (maybe problem is here?)
intentOne.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
Try add android:launchMode="singleInstance" android:excludeFromRecents="true" android:noHistory="true" and in AndroidMainfest
just add android:noHistory="true" to the activity manifest.
http://developer.android.com/guide/topics/manifest/activity-element.html#nohist
android:noHistory
Whether or not the activity should be removed from the activity stack and finished (its finish() method called) when the user navigates away from it and it's no longer visible on screen — "true" if it should be finished, and "false" if not. The default value is "false".
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.
This attribute was introduced in API Level 3.
I have an activity that performs a small bit of code and then calls finish. This works fine and the activity goes away, but if I press the history button (if it's called the history button?) the activity still appears to be there, though clicking it will do nothing.
I have enabled android:noHistory="true" in my manifest. I only have a single activity that changes some settings, and then calls finish, nothing else.
Is there a way for me to make that trace of the activity go away?
Assuming that the history button you refer to is the list of recent apps, you can set
android:excludeFromRecents="true"
By default value for this attribute is false.
For other attributes check the link: http://developer.android.com/guide/topics/manifest/activity-element.html
So here is my activity.
<activity
android:name=".MainActivity_Hard"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/title_activity_main_activity__hard"
android:noHistory="true"
android:screenOrientation="portrait" >
</activity>
I marked it as android:noHistory="true" because I did not want the screen to be added to the activity stack.
But however when I lock the screen and unlock it. The activity disappears and the previous screen appears. This should not happen. Could anyone tell me why.
Note: It happens in ICS (Samsung Galaxy Note), but not with previous devices (Gingerbread,etc.)
Setting the noHistory attribute in your activity means that as soon as the user navigates away from that activity--bringing up the lock screen included--its finish() function is called automatically, thus destroying it and going back to the previous activity that spawned it.
This is typically used for splash-screen-type activities which, for example, acts only as a launcher and you don't want the user to be able to go back to the splash screen from the child.
If this is not your intention, then you should consider removing the noHistory attribute and maybe managing the activity lifecycle yourself. (For example, if you don't want your activity to be in the stack, then just call finish() just after it starts another activity.)
android:noHistory
Whether or not the activity should be removed from
the activity stack and finished (its finish() method called) when the
user navigates away from it and it's no longer visible on screen —
"true" if it should be finished, and "false" if not. The default value
is "false". 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.
I don't know why. But if you don't want to add this activity to current stack. You can set android:launchMode="singleTask". When start this activity it will be added to it own stack.
You can see more here enter link description here
Hope it help :)
In AndroidManifest.xml put this permission tag above application tag.
<uses-permission android:name="android.permission.WAKE_LOCK" />
In my app I have couple activities. How to setup that every time user long press home and bring from background my app it display always main activity?
Cause right now if user hide the app and log press "home" button, my app coming back to the latest open activity, but then user press "back" button it close app, but than press app icon it coming back to main activity.
If you want only your main activity to be in visible your "recent apps", then in all your non-main activities, add this flag in your manifest:
android:noHistory
This will cause your main activity to remain on the activity stack, but remove all your activities from it.
http://developer.android.com/guide/topics/manifest/activity-element.html#nohist
Whether or not the activity should be removed from the activity stack
and finished (its finish() method called) when the user navigates away
from it and it's no longer visible on screen — "true" if it should be
finished, and "false" if not. The default value is "false". 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. This attribute was introduced in API
Level 3.
I don't want the user to be able to go back to the splashscreen of my app. One solution seems to be to check if the activity below the current one is an instance of the splashscreen, and in that case exit the app, as shown in the code below. However, I don't know how to check what's the previous activity in the stack. Anybody can help? Is there any other way to disable 'go back' to a given activity?
#Override
public void onBackPressed() {
if(<previous activity in stack is an instance of splashscreen>){
Intent exit_intent=new Intent(CurrentActivity.this, SplashScreen.class);
exit_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
exit_intent.putExtra("EXIT", true);
context.startActivity(exit_intent);
}
}
Call finish() in your Splash Screen activity right after starting the next activity.
Another approach is to add this attribute to your activity in AndroidManifest.xml: android:noHistory="true"
Example:
<activity android:name=".SplashActivity" android:noHistory="true"/>
This attribute instructs Android to remove SplashActivity from the history stack once its navigated away from.
Just call context.finish() after context.startActivity()
try the following when calling the next Activity from your Splashscreen:
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
<activity android:name=".SplashActivity" android:noHistory="true"/>
From the documentation:
Whether or not the activity should be removed from the activity stack
and finished (its finish() method called) when the user navigates away
from it and it's no longer visible on screen — "true" if it should be
finished, and "false" if not. The default value is "false".
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. In this case,
onActivityResult() is never called if you start another activity for a
result from this activity.
This attribute was introduced in API Level 3.