pressing Home键后的And​​r​​oid服务运行 [英] Android service running after pressing Home key

查看:50
本文介绍了pressing Home键后的And​​r​​oid服务运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android服务,使用StartService在OnCreate中创建的应用程序的第一个活动的()。我需要整个应用程序的寿命是运行该服务例如,所有的活动中的应用。但该服务不应该在pssed用户$ P $ HOME键或返回按钮所消耗的资源。有没有优雅的方式来做到这一点以外的其他的onPause停止所有活动的service()方法?

I have an Android service, created in OnCreate of first Activity of the application using StartService(). I need this service to be running throughout the life span of the application ie, all the activities in the application. But the service should not consume the resources after user pressed Home key or Back button. Is there any elegant way to do that other than stopping the service in onPause() method of all the activities?

推荐答案

您可以做什么达雷尔建议,但摆在扩展活动一类新的code,然后扩展了你的所有正常活动。

You could do what Darrell suggests but put that code in a new class that extends Activity and then extend that on all your normal Activities.

我不知道实现自己的目标的任何其他的更优雅的方式。

I don't know any other more elegant way of achieving your goals.

这篇关于pressing Home键后的And​​r​​oid服务运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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