开发者

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 pro开发者_如何学JAVAgram 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜