从EXTERN活动服务访问处理器 [英] Access an handler in service from extern activity

查看:92
本文介绍了从EXTERN活动服务访问处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

香港专业教育学院设置在正在运行的服务的处理程序做哪些操作每隔X时间。

现在一定时间后,我要开始从该服务的活动,并在活动的onCreate我想访问服务(启动acitivty)的该处理程序,并停止它的schedualed操作

 (mHandler.removeCallbacks(someTask));

任何想法,我将如何访问处理器这是在服务?

服务和被叫活动是在同一proccess

感谢,

射线。


解决方案

  

香港专业教育学院设置在运行服务
  该处理器运行是否每隔X
  时间。


为什么呢?你并不需要一个处理程序服务

如果每X时间是指你有一个繁忙的循环,或正在使用的TimerTask ,或什么东西,请考虑是否 AlarmManager 可能是一个更好的解决方案。


  

现在一定时间后,我要开始
  从服务活动


如果有一个在前台你的一些其他活动,这是奇怪,但可以接受。但是,如果你的计划是他们的游戏,电话,短信,或任何与活动期间中断用户,用户将可能给你一个一星级的市场,如果你不能证明入侵。


  

任何想法,我将如何进入处理程序
  这是在服务?


简单:摆脱处理程序,而且你不必担心停止它。你并不需要一个处理程序服务

Ive set an in a running service a handler which does operation every X time.

Now after certain time i wanna start an activity from that service, and in onCreate of the activity i wanna access that handler of the service(which started the acitivty) and stop it's schedualed operation

 (mHandler.removeCallbacks(someTask)); 

any idea how will i access the handler which is in the service?

the service and the called activity are in the same proccess.

thanks,

ray.

解决方案

Ive set an in a running service a handler which does operation every X time.

Why? You do not need a Handler in a Service.

And if "every X time" means you have a busy loop, or are using TimerTask, or something, please consider whether AlarmManager is possibly a better solution.

Now after certain time i wanna start an activity from that service

If there is some other activity of yours in the foreground, this is strange but acceptable. However, if your plan is to interrupt the user during their game, phone call, text message, or whatever with your activity, users will probably give you a one-star rating on the Market if you cannot justify the intrusion.

any idea how will i access the handler which is in the service?

Simple: get rid of the Handler, and you do not have to worry about stopping it. You do not need a Handler in a Service.

这篇关于从EXTERN活动服务访问处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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