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.
Why? You do not need a
Handlerin aService.And if “every X time” means you have a busy loop, or are using
TimerTask, or something, please consider whetherAlarmManageris possibly a better solution.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.
Simple: get rid of the
Handler, and you do not have to worry about stopping it. You do not need aHandlerin aService.