0

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?

  • Try `finishAndRemoveTask()`: https://developer.android.com/reference/android/app/Activity#finishAndRemoveTask() – CommonsWare May 21 '20 at 13:56

1 Answers1

-1

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.

Akshay Rajput
  • 250
  • 4
  • 11
  • First of all thank you so much for your answer. I just change public void closeApp(View v){ finish(); } to @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void closeApp(View v){ finishAndRemoveTask(); } – Onur Tekin Gündoğdu May 21 '20 at 14:38
  • I did not understand is this answer is useful for you or not? – Akshay Rajput May 21 '20 at 14:48