运行code时,Android应用程序被关闭/发送至后台应用程序、后台、发送至、code

由网友(几曾有)分享简介:我有一个Android应用程序,它发送一些数据到一个web服务。我需要尽快发送该数据作为应用程序被关闭或发送至后台。但是我怎么做到这一点?I have an Android application which sends some data to a webservice. I need to send this d...

我有一个Android应用程序,它发送一些数据到一个web服务。我需要尽快发送该数据作为应用程序被关闭或发送至后台。但是我怎么做到这一点?

I have an Android application which sends some data to a webservice. I need to send this data as soon as the application is closed or sent to background.. But how do I accomplish this?

我目前的解决方案是在我家上的活动将OnPause运行(),但我需要它来运行,无论哪个活动用户关闭应用程序时对..这可能还是我来添加将OnPause方法的所有活动?

My current solution is to run it on the OnPause() on my home activity, but I need this to run no matter which activity the user is on when closing the app.. Is this possible or do I have to add the OnPause method to all activities?

推荐答案

修改

这个答案只服务于一个目的,那就是运行code。在的onPause()的所有活动。它不会让你运行一个code,当你的应用程序发送到后台。

This answer only serves for one purpose, that is, running a code in onPause() for all activities. It doesn't let you run a code when your app is sent to background.

原来的答案

请名为 YourBasicActivity 的活动并覆盖其的onPause()的方法,并从 YourBasicActivity

Make an Activity named YourBasicActivity and override its onPause() method and extend every Activity from YourBasicActivity

阅读全文

相关推荐

最新文章