在应用程序关闭时编写侦听器 [英] write listener when application close

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

问题描述

我想在应用程序关闭时编写代码.我想为应用程序编写侦听器.我已经创建了Application类,但是在活动中找不到像onCreatedonDestroy方法那样的任何适当方法.

I want to write code when application close. I want to write listener for application. I have created Application class but does not find any appropriate method as like onCreated and onDestroy method in activity..

推荐答案

简短的答案是……没有!

The short answer is ... there aren't!

关闭应用程序"的概念非常分散:应用程序是一组活动,服务等,并且很多事情可以使该应用程序保持活动状态.

The concept of "application close" is very diffuse: An application is a set of activities, services, etc... and a lot of things may keep the application alive.

您甚至无法猜测何时(或是否)将调用活动onStop()onDestroy().

You can't even guess when (or if) an activity onStop() and onDestroy() will be called.

即使调用activity.finish()也不意味着这些方法中的任何一种都会被立即调用.看看 http://developer.android.com/training/basics /activity-lifecycle/stopping.html .

Even calling activity.finish() doesn't mean any of those methods would be called instantly. Take a look at http://developer.android.com/training/basics/activity-lifecycle/stopping.html .

但是,肯定有一个更好的地方来做您必须做的事情.什么事?

But there's sure a better place to do those things you have to do. What is it?

这篇关于在应用程序关闭时编写侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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