在Android Lifecycle中,当从最近的应用列表中刷新应用时,是否有任何唯一的方法?

发布于 2025-02-06 08:15:05 字数 94 浏览 1 评论 0原文

在Android Lifecycle中,当应用程序从最近的应用列表中刷卡时,是否有任何独特的方法可以调用?我们最初认为我们会使用Ondestroy,但在其他活动中也会被调用。

In android lifecycle, is there any unique method that gets called when the app is swiped from the recent app list? We initially thought we would use onDestroy but it gets called during other activities as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许仙没带伞 2025-02-13 08:15:05

添加下面的服务并开始。当应用关闭OnTaskRemaved运行您的代码时。

清单

<service
    android:enabled="true"
    android:name=".ExitService"
    android:exported="false"
    android:stopWithTask="false" />

服务类

public class ExitService extends Service {

@Override
public void onStartService() {}

@Override
public void onTaskRemoved(Intent rootIntent) {
    super.onTaskRemoved(rootIntent);
    this.stopSelf();
}}

Add a service like below and start it. When app close onTaskRemoved run your code.

Manifest

<service
    android:enabled="true"
    android:name=".ExitService"
    android:exported="false"
    android:stopWithTask="false" />

Service class

public class ExitService extends Service {

@Override
public void onStartService() {}

@Override
public void onTaskRemoved(Intent rootIntent) {
    super.onTaskRemoved(rootIntent);
    this.stopSelf();
}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文