0

I have an Android Service that starts up an admin Android application at boot time. Note that I cannot do away with the app as I need it for admin interaction.

The Android Service + app is the server to around 10 Android clients over a LAN connection. I plan to use nanohttpd (a very light-weight http server) to act as http server for communication with the clients. Now, the question is, should I implement nanohttpd in the Service part or in the app part of the server? What is the best approach?

Stephan
  • 41,764
  • 65
  • 238
  • 329
Srikanth
  • 2,014
  • 19
  • 22

2 Answers2

2

Definitely use Service, they are just exactly what you need - a lot of work in the background.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
  • If implemented as a Service, I need the service to run forever since it is a server. In my case, the admin app is designed to run in Kiosk mode (homescreen app with every other access disabled). I came across bound services (http://developer.android.com/guide/components/bound-services.html). So, binding the service to my admin app will ensure that the server always runs. Am I right or is that a bad idea? – Srikanth Mar 15 '13 at 12:05
  • Yes, your idea of binding to UI is perfectly fine. Android tries hard to keep alive the services connected to currently showing activities. – Vladimir Ivanov Mar 15 '13 at 12:38
0

Services will always run until you stop them, so yes, that is the way to do it.

Nova Entropy
  • 5,727
  • 1
  • 19
  • 32
  • not really. they will run for ~30 minutes, then be killed. (unless you foreground them) – njzk2 Mar 15 '13 at 09:29