1

I am creating a application that provides a Service for use by multiple 3rd parties. It also has a front-end UI that the user can access to manage the service and its interactions with other applications. For stability reasons I have currently set up the service to run in a separate process from the UI. I need to share state between the UI and the service. 3rd parties interact via a Messenger interface. I do not want to have to deal with this overhead of messages for simply reading a boolean flag in the service from a UI activity within the application. I have attempted to use a subclass of Application to share state, but as noted here this does not work across processes, which I have verified. What other mechanism is there for this purpose that works?

Thanks in advance.

Community
  • 1
  • 1
Dylan
  • 1,692
  • 1
  • 13
  • 24
  • `For stability reasons I have currently set up the service to run in a separate process from the UI` is this a choice? – Sherif elKhatib Aug 01 '11 at 11:11
  • Well, if the UI crashes for any reason, I do not want the service to be affected. – Dylan Aug 01 '11 at 12:38
  • as long as you start the service using startservice it will become independent from the activity – Sherif elKhatib Aug 01 '11 at 12:42
  • I need bindService, but I use startService to start the service beforehand. However, in my testing, force closes on the UI cause the entire process to die. This does not happen with separate processes. – Dylan Aug 01 '11 at 12:52
  • "I need bindService" -- why? "However, in my testing, force closes on the UI cause the entire process to die." -- not as far as I am aware, at least if you use `startService()` instead of `bindService()`. "This does not happen with separate processes." -- separate processes also waste RAM, CPU, and battery. Use `Thread.setDefaultUncaughtExceptionHandler()` so you do not need to waste resources to get your desired stability. – CommonsWare Aug 01 '11 at 16:06
  • I need `bindSerivce` for the Messenger interface to work, as far as I am aware. It is used in the Messenger samples. I call `startService` immediately before `bindService`. Is there a problem with that? The service needs to start when required, be bound to any number of different applications, and still hang around after processes unbind (unless system resources are compromised), as it persists a login state that may be used later. Thanks for the tip about `setDefaultUncaughtExceptionHandler`. I will definitely use that. However the question remains open out of curiosity. – Dylan Aug 02 '11 at 10:02

0 Answers0