Why does a shortcut to a secondary activity opens the main activity while in the background?

坚强是说给别人听的谎言 提交于 2019-12-11 03:59:41

问题


My app has several activities, one of which has life in its own right, so I made a shortcut to it in the manifest via:

        <intent-filter>
            <action android:name="android.intent.action.CREATE_SHORTCUT" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

Now I have it in the Widgets zone. This secondary activity now opens when I click the shortcut that I put in my launcher, as I wanted.

However, there is something that does not work as I want: if the main app is working in the background (say, via the home button), clicking the secondary activity shortcut pop-ups the main app, not the secondary activity.

Why is that? Is this the natural behavior? Is there a way to open the secondary activity always, even side by side with the main app?

Thanks!

L.


回答1:


By surfing other stuff I found the solution of this. Just add

 android:launchMode="singleInstance"

in the secondary <activity> in the manifest. Here is the explanation: http://developer.android.com/guide/topics/manifest/activity-element.html#lmode



来源:https://stackoverflow.com/questions/22799461/why-does-a-shortcut-to-a-secondary-activity-opens-the-main-activity-while-in-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!