When my activity is running if the user presses backPressed, the activity is dismissed and it is not visible in the recent apps list. I want it to be shown in the recent apps list. How can I do that?
@Override
public void onBackPressed() {
super.onBackPressed();
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
Manifest:
<activity
android:name=".MyActivity"
android:configChanges="mcc|mnc|locale|touchscreen
|keyboard|keyboardHidden
|navigation|orientation
|screenLayout|screenSize
|fontScale"
android:excludeFromRecents="true"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
Remove this line form AndroidManifest
android:excludeFromRecents="true"
OR set it false
android:excludeFromRecents="false"
i think @begiNNer want's to remove the recent application(means last used application) from the device like CleanMaster application. So you have to get the pid of the running application than remove one by one, If this is the case than the below code will works.
Code:
activityManager.killBackgroundProcess(pid);
android.os.Process.killProcess(pid);
get pid Code:
ActivityManager am = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> pids = am.getRunningAppProcesses();
int processid = 0;
for (int i = 0; i < pids.size(); i++) {
ActivityManager.RunningAppProcessInfo info = pids.get(i);
System.out.println(info.pid);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.