替代Intent.FLAG_ACTIVITY_CLEAR_TASKIntent、FLAG_ACTIVITY_CLEAR_TASK

2023-09-06 01:31:11 作者:木槿暖夏

我有两个应用程序应用-B发射应用-A。如果用户启动应用程序b从内部在App-A应用AI通话结束,所以我没有任何问题。

I have two apps App-B launches App-A. If the user starts App B from inside App A I call finish on App-A so I have no problem.

如果用户去直接附录二从应用程序的抽屉或长pressing回家按钮,然后我实现了第一次申请所有的演员之前低于它清除在应用程序中的任务。这所期望的影响,但只适用于API 11.在较低的原料药在APP-A的新任务不会改变,群众演员putExtra将没有任何效果。任何替代 FLAG_ACTIVITY_CLEAR_TASK ?对于API< = 10

If the user goes straight to App B from the Application drawer or long pressing home button then I implement the below which clears the task in App A first before applying all the extras. This has the desired affect but only works on API 11. On lower APIs the new task in APP-A will not change and extras putExtra will have no effect. Any alternative to FLAG_ACTIVITY_CLEAR_TASK? for API <=10?

        Intent i = new Intent("com.App-A");
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

感谢

杰森

推荐答案

新的 IntentCompat 应该已经帮助上,但显然标志被忽略的API低于11。

The new IntentCompat should've helped on that, but apparently the flag is ignored for API lower than 11.

要使用IntentCompat做到以下几点:

To use IntentCompat do following:

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
 
精彩推荐
图片推荐