tags:

views:

45

answers:

1

Hi all,

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.

A: 

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.

CommonsWare
I need a Handler in my Service, coz i wanted scheduale time task.and i wont interrupt the user with any upcoming activity. that wasnt the purpose."and you do not have to worry about stopping i", why not? i have to stop it, coz else the scheduale task will keep on working.(and i do need the service to work without those scheduale tasks ive made)
rayman
"get rid of the Handler, and you do not have to worry about stopping it. You do not need a Handler in a Service." what else then?
rayman
Ive also read in many places it's better use the handler timing then the TimerTask, Any reason for that? would like to hear your recommends.
rayman