Shortcut from Recent Applications always launch la

2020-08-05 10:26发布

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

4条回答
Luminary・发光体
2楼-- · 2020-08-05 10:37

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.

查看更多
放荡不羁爱自由
3楼-- · 2020-08-05 10:42

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.

查看更多
Emotional °昔
4楼-- · 2020-08-05 10:45

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.

查看更多
劫难
5楼-- · 2020-08-05 10:53

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.

查看更多
登录 后发表回答