关闭应用程序时调用了什么方法 [英] What method is being called when I close an app

查看:16
本文介绍了关闭应用程序时调用了什么方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了有关 Activity 生命周期及其方法的所有信息.

I read all about the activity lifecycle and it's methods.

我还是找不到答案:当我关闭我的应用程序时,从打开应用程序"菜单(在galaxy4 中长按主页按钮,在nexus5 中它是右键...)调用什么方法?如果有?

I still couldt find an answer: When I close my app, from the "open apps" menu (in galaxy4 it's a long press on the home button, in nexus5 it's the right button ...) what method is being called? if any?

换句话说,我的活动是启动一项服务.如果应用程序(活动)正在关闭,我想终止服务.(onDestory 根本不可靠,正如前面多次说过的那样)

In other words, my activity is launching a service. I want to terminate the service if the app (activity) is being closed. (onDestory is not reliable at all as said many times here before)

提前致谢!

推荐答案

onPause() 是唯一始终调用的方法.从 onPause() 状态 Android 操作系统可以出于多种原因绕过 onStop 和 onDestroy 杀死此应用程序.我认为我们无法顺利控制这种意外终止的行为.服务可以定期检查应用程序的状态.

onPause() is the only method that is called always. From onPause() state Android OS can kill this app for many reasons bypassing onStop and onDestroy. I don't think we can control this behavior of unexpected termination smoothly. Service can check for the state of the application periodically.

这篇关于关闭应用程序时调用了什么方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆