关闭 android 个应用时

When shut down android app

kil 处理应用程序时如何获取。例如

当一位客户要终止我的应用程序时。我想了解这种状态,所以当应用程序被杀死时。 onDestroy 方法不起作用。我需要替代品。

public class LoginActivity 扩展 AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

}

@Override
protected void onDestroy() {
    super.onDestroy();
    Log.e("Activity","destroy");
}

}

你做不到。最后调用的最后一个生命周期调用是 onPause。没有其他保证。

如此处所述:

When a user or the system force stops your application, the entire process is simply killed. There is no callback made to inform you that this has happened.

When the user uninstalls the app, at first the process is killed, then your apk file and data directory are deleted, along with the records in Package Manager that tell other apps which intent filters you've registered for.