1

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.

rayman
  • 20,786
  • 45
  • 148
  • 246
  • I though about doing some static class, with a flag and adjust that flag via the service and the acitivty.. but is it a good idea? not the most OOP thingy to do;P – rayman Jun 23 '10 at 08:03

1 Answers1

0

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
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 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 Jun 27 '10 at 06:29
  • "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 Jun 28 '10 at 06:11
  • 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 Jun 28 '10 at 06:29