Android Studio- How To Delete Recent App List Programmatically After Application Closed

102 Views Asked by At

when I close my application I want to remove it from the "recent app list" also in android.

I created an empty project and activity.

Here my main XML file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.rebirthing.clear_recent_list_app.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    android:onClick="closeApp"
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

Here My MainActivity.java file:

`package com.example.rebirthing.clear_recent_list_app;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
public void closeApp(View v){
    finish();
}
}
`

When I click the TextView which inside of my Xml File. It closes my App. but when I Check "Recent App List" its still there. How do I fix it?

1

There are 1 best solutions below

2
On

if you want to do something with your app when you close your application. then use this method

 protected void onDestroy() {
      super.onDestroy();
      //do what you want to do here
   }

this method is called when you close your application.

if you find this answer useful then please mark it correct.