机器人:如何检查,如果应用程序在后台运行机器人、应用程序、后台

2023-09-12 06:34:25 作者:黒 心情如何、

我是新手到Android。我的客户端服务器应用程序。服务器不断每一分钟后,在客户端发送更新通知到客户端我的应用程序接收这些更新和使用吐司显示。但现在我的问题是,每当我的客户端应用程序进入后台服务器不断发送更新通知,我的客户端显示为如果应用程序是在前台。我没有得到如何检查应用程序在后台运行。

I am newbie to android. I have client server based application. Server keeps on sending the update notifications to client after every single minute and at client side my app receive those updates and display it using Toast. But now my problem is whenever my client app goes into the background server keeps on sending the update notifications and my client display it as if the application is in foreground. I am not getting how to check that application is running in background.

推荐答案

http://developer.android.com/guide/topics/fundamentals.html#lcycles是一个Android应用程序的生命周期的描述。

http://developer.android.com/guide/topics/fundamentals.html#lcycles is a description of the Life Cycle of an android application.

该方法的onPause()被调用时,活动进入后台。所以,你可以禁用更新通知,这种方法。

The method onPause() gets called when the activity goes into the background. So you can deactivate the update notifications in this method.