How to exclude from recents an exported activity? - android

I have an app with an exported activity that can be invoked from other apps (Specifically the sharing action - android.intent.action.SEND)
How can an exported activity be excluded from recents?
I don't see a way to set the FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS flag, because it is invoked from the outside.
The reason I want to do this is because this intent becomes the last one in my activity stack, thus when clicking on the recents, a file is being re-shared instead of the main activity to pop up.
Note: android:launchMode="singleTask" solves the problem in a specific case, only where another activity is on top. BUT, this isn't an option because it disrupts the user task flow and doesn't work if there is no other app's activity at the root.

You can add the android:excludeFromRecents attirbute to your <activity> element in the manifest with a value of true:
<activity
android:name="XYZ"
android:excludeFromRecents="true">

Related

How to close activity, so cannot be opened again from active apps?

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.

Stopping multiple activities from showing up

I have it so when you click the notification icon on my app it opens up an activity. The thing is that if you click it over and over it opens the same activity over and over. So when you click the back button you have to go through all of those before going back to the beginning. How could I make it so that if that activity is already there it doesn't reopen it?
Check out the launchMode section of the manifest documentation.
You're looking to add:
android:launchMode="singleTop"
to the declaration for your Activity in the manifest. This means that if an instance of the activity is already at the top of the target task, the system will re-use that. Any intent gets delivered to the onNewIntent method of that activity.
I'd recommend having a good read of all the options on that page and deciding which one is right for your usage.
Try putting this in your manifest:
android:launchMode="singleTop"

Android Start Activity from a service without starting the other activities of the app

I am starting an activity with Theme.Dialog on IncomingCall detected; however, when I start my dialog activity, it hides the Incoming Call Screen which is not the behavior I want. I want to start that dialog activity alone so that it appears on top of the incoming call screen and NOT the WHOLE application on top of the incoming call screen. I used the SingleTask in the Manifest and the NEW_TASK flag and used all sorts of Contexts.
as a hint, I want to do something like TrueCaller Android App.
You need to make sure that the activity with Dialog theme has a different task affinity than the rest of your app. Otherwise, if your app is running, launching that activity (even with FLAG_ACTIVITY_NEW_TASK) will just bring the existing task forward and put your activity on top of that.
You should add the following to the manifest for this specific activity:
android:taskAffinity=""
android:noHistory="true"
android:excludeFromRecents="true"
NOTE: Setting noHistory and excludeFromRecentsensures that this task does NOT show up in the "recent tasks list".
use android:launchMode="singleInstance"

Current Activity disappearing when screen gets locked

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" />

Shortcut from Recent Applications always launch latest activity of application. How to change that?

I would like to launch always a specific activity, not this which was active during closing application. I don't have possibility switching to desirable activity before closing, because it could be dead.
I would prefer even delete shortcut to whole program from recent app than make user confused by launch credits instead of start splash screen. However this would be only workaround (but just in case, how can I do that?)
I decompiled some apps and found their solution:
<android:name="..."
android:taskAffinity=":shortcut"
android:excludeFromRecents="true"
android:clearTaskOnLaunch="true"
...
About android:taskAffinity:
An affinity name that applies to all activities within the application, except for those that set a different affinity with their own taskAffinity attributes. See that attribute for more information.
By default, all activities within an application share the same affinity. The name of that affinity is the same as the package name set by the <manifest> element.
If you mean you want to start your application through the same activity every time, add
android:launchMode="singleTask"
to your main activity in the manifest file. This will force your application to put this activity at the bottom of the activity stack clearing all other activities which may have been running.
One way you can achieve this would be to mark all your activities with android:excludeFromRecents="true" attribute. this would ensure that none of your activities shows in the Recent Applications list.
You should also look into the android:finishOnTaskLaunch and android:stateNotNeeded attributes.
The correct way to solve this is to add
android:noHistory="true"
to the manifest entry for all activities except for the main (root) Activity.
When the user returns to your application, either from the list of recent tasks or by pressing the app icon on the HOME page, all activities (except for the main (root) Activity) will be removed from the task (actually, they get removed immediately when the user navigates away from the app by pressing the HOME button, answering an incoming phone call, choosing another app from the Notification bar, etc.

Categories

Resources