在 Android 系统中,如果我们不想某个 Activity 出现在 “Recent screens” 中,可以设置 属性 android:excludeFromRecents 为 true。其中有些需要注意到的地方说明下。
android:excludeFromRecents 属性并不会仅仅影响被设置的 Activity。由此该 Activity 启动的后续同属一个 “Task” 的一系列 Activity 都不会出现在 Recent screens。也就是说该属性是对 Task 起作用的,而不仅仅是某个 Activity。
具体功能如下:
PackageManager packageManager4 = getApplicationContext().getPackageManager();
Intent intent_screenshot = packageManager4.getLaunchIntentForPackage("com.xinrui.screenshot");
intent_screenshot.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//新开启一个Task
startActivity(intent_screenshot);
- screenshot app的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xinrui.screenshot">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true">
<activity android:name=".MainActivity"
android:theme="@style/notitle"
android:launchMode="singleTask"
android:excludeFromRecents="true"--重点就是这里的配置>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ScreenCaptureActivity"
android:theme="@style/notitle"
/>
</application>
</manifest>