どのようにAndroidの「ホーム」のショートカットが、それは歴史のだしポイントだアプリをバイパスするのですか?

StackOverflow https://stackoverflow.com/questions/978172

質問

私は、あなたが特定のActivityにホーム「ショートカット」を作成することを可能にするアプリを持っています。それは、私のユーザーのいくつかのアプリを使用することが判明何かを行う行くためにホームキーを押し、その後、戻ってその活動にジャンプするショートカットのいずれかを使用します。アプリがメモリ内に残っているので、それだけで他の人の上に新しいActivityを開き、「戻る」キーは、全体の履歴を戻ってそれらを取るでしょう。彼らは効果的に歴史を殺すために、ショートカットを使用して、バックキーだけでアプリを終了している場合は何が起こる持っているしたいことです。任意の提案ですか?

役に立ちましたか?

解決

まず、href="http://developer.android.com/guide/topics/manifest/activity-element.html#aff" rel="nofollow noreferrer"> 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