特定の へのホーム「ショートカット」を作成できるアプリがありますActivity。一部のユーザーはアプリを使用し、ホーム キーを押して別のことを行い、ショートカットの 1 つを使用してそのアクティビティに戻ります。アプリはまだメモリ内にあるため、他のアプリの上に新しいアプリを開くだけActivityで、「戻る」キーを押すと履歴全体に戻ります。私が望んでいるのは、ショートカットを使用して履歴を効果的に削除し、戻るキーでアプリを終了させることです。助言がありますか?
10422 次
2 に答える
6
まず、マニフェストで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_TASKと FLAG_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);
于 2009-10-27T20:25:13.840 に答える
1
Intent.FLAG_NEW_TASKIntent に追加してみてください。
于 2009-06-10T23:06:53.063 に答える