我有一个应用程序,允许你创建首页“快捷方式”,以一个特定的Activity。事实证明,我的一些用户使用的应用程序,打的Home键去做些别的事情,然后使用快捷键一个跳回到该活动。由于应用程序仍在内存中它只是打开的人,和“返回”键,顶部的新Activity会带他们回来贯穿整个历史。如果他们使用的快捷方式,然后以有效杀灭历史,有返回键只是退出程序我想有发生的。任何建议?

有帮助吗?

解决方案

首先,设置在 taskAffinity 在舱单使Activity运行作为一个不同的“任务”:

<activity
        android:taskAffinity="" 
        android:name=".IncomingShortcutActivity">
        <intent-filter>
            <action android:name="com.example.App.Shortcut"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
</activity>

然后,构建快捷时,设置FLAG_ACTIVITY_NEW_TASKFLAG_ACTIVITY_CLEAR_TOP标志。是这样的:

// build the shortcut's intents
final Intent shortcutIntent = new Intent();
shortcutIntent.setComponent(new ComponentName(this.getPackageName(), ".IncomingShortcutActivity"));
shortcutIntent.putExtra(EXTRA_STOPID, Integer.toString(this.stop_id));
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// Sets the custom shortcut's title
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, custom_title);
// Set the custom shortcut icon
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.bus_stop_icon));
// add the shortcut
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);

其他提示

尝试增加Intent.FLAG_NEW_TASK到的意图。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top