私が知っているように、アクティビティの明確な履歴が必要な場合は、2 つの方法で行うことができます
(1)。manifest.xml ファイル内
AndroidManifest.xml ファイルからこれを実装することもできます。必要な属性にandroid:noHistory="true"属性を追加するだけです。
例
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rdc.activity"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="xx" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".PickGalleryImageActivity"
android:label="@string/app_name"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
(2)。Java コードで
アクティビティを開始するときにこのフラグを追加できますIntent.FLAG_ACTIVITY_NO_HISTORY
例
Intent intent = new Intent(this, SomeOtherClass.class);
// do not keep this intent in history
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
もう 1 つは、例の下の [戻る] ボタンの突き刺しを探している場合に役立つ場合があります。
1.6 までの Android API レベルを探している場合。
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//todo here
return true;
}
return super.onKeyDown(keyCode, event);
}
それがあなたを助けることを願っています!!