如何检测当一个Android应用程序转到后台,回来到前台 [英] How to detect when an Android app goes to the background and come back to the foreground

查看:128
本文介绍了如何检测当一个Android应用程序转到后台,回来到前台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个应用程序,并具体的东西时,它一定的时间后,带回了前台。有没有一种方法来检测,当一个应用程序发送到后台或提请前景?

I am trying to write an app that does something specific when it is brought back to the foreground after some amount of time. Is there a way to detect when an app is sent to the background or brought to the foreground?

推荐答案

的onPause() onResume()方法被调用时,应用程序被带到背景并进入前景再次。然而,它们也被称为当应用程序被启动的第一时间,它被杀死之前。你可以阅读更多的 活动 的。

The onPause() and onResume() methods are called when the application is brought to the background and into the foreground again. However, they are also called when the application is started for the first time and before it is killed. You can read more in Activity.

没有任何直接的方法来获得在背景或前景,而应用程序的状态,但即使我面临这个问题,并发现了 onWindowFocusChanged 解决方案和的onStop

There isn't any direct approach to get the application status while in the background or foreground, but even I have faced this issue and found the solution with onWindowFocusChanged and onStop.

有关详细信息检查这里的 <一个href="http://vardhan-justlikethat.blogspot.in/2013/05/android-solution-to-detect-when-android.html">Android:解决方法来检测当一个Android应用程序转到后台,回来到前台没有getRunningTasks或getRunningAppProcesses 的。

For more details check here Android: Solution to detect when an Android app goes to the background and come back to the foreground without getRunningTasks or getRunningAppProcesses.

这篇关于如何检测当一个Android应用程序转到后台,回来到前台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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