I built an application for Android to auto-login to a specific Guest wireless network. I wanted this application to work and run even when the UI/Activity is not shown/running.
Currently it seems to work well, however I'm questioning the logistics of the design. My questions are:
- Do I even need a service?
- Is my design backwards? Should the Broadcast Receiver call the service to do the work?
- Can you register the broadcast receiver in the manifest and not have to call it at all in code?
- Are multiple calls to startService() bad? I know only 1 service runs, but how do I check if the service is already running before creating it?
The application has 3 components:
- Activity - which has a GUI for displaying current network information and Close / "Stop Service" buttons
- Service - all this service does is register a broadcast receiver
Broadcast Receiver - this is what does most of the work. 3.
- The Activity's onCreate() calls the Context.startService()
- The Service onCreate() creates a notification icon and registers the broadcast receiver
- The Broadcast Receiver onReceive() checks if the network state has changed intent, then checks if currently connected to a specific SSID, then calls a special class I made to register / check if authenticated.