【问题标题】:Android Studio- How To Delete Recent App List Programmatically After Application ClosedAndroid Studio-如何在应用程序关闭后以编程方式删除最近的应用程序列表
【发布时间】:2020-05-21 13:46:27
【问题描述】:

当我关闭我的应用程序时,我想将其从 Android 中的“最近的应用程序列表”中删除。

我创建了一个空项目和活动。

这是我的主要 XML 文件:

<?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>

这里是我的 MainActivity.java 文件:

`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();
}
}
`

当我单击我的 Xml 文件中的 TextView 时。它关闭了我的应用程序。但是当我检查“最近的应用程序列表”时它仍然存在。我该如何解决?

【问题讨论】:

标签: android android-studio activity-finish close-application


【解决方案1】:

如果您想在关闭应用程序时对应用程序执行某些操作。 那就用这个方法

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

当您关闭应用程序时会调用此方法。

如果您觉得此答案有用,请标记为正确。

【讨论】:

  • 首先非常感谢您的回答。我只是更改 public void closeApp(View v){ finish(); } to @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void closeApp(View v){ finishAndRemoveTask(); }
  • 我不明白这个答案对你有用吗?
猜你喜欢
  • 2012-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-05
  • 1970-01-01
  • 2012-05-16
  • 2014-07-16
  • 1970-01-01
相关资源
最近更新 更多