运行code时,Android应用程序被关闭/发送至后台 [英] Run code when Android app is closed/sent to background

查看:136
本文介绍了运行code时,Android应用程序被关闭/发送至后台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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()的方法,并从<$ C $扩展的每个活动C> YourBasicActivity

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

这篇关于运行code时,Android应用程序被关闭/发送至后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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