Proper use of background service / broadcast receiver

I created an Android app to automatically log into a specific guest wireless network. I wanted this application to work and start even when the UI / Activity is not displayed / working.

Currently it works well, however I doubt the design logistics. My questions:

  • Do I need a service?
  • Is my design back? Should a broadcast receiver call a service to do this?
  • Can you register a broadcast receiver in a manifest and not have to call it in code at all?
  • Are multiple startService () calls bad? I know only 1 start of the service, but how to check if the service is running before creating it?

The application has 3 components:

  • Activity - which has a graphical interface for displaying current network information and the Close / Stop Service buttons
  • Service β€” This entire service is registering a broadcast receiver.
  • A broadcast receiver is what does most of the work. 3.

    • The onCreate () action calls Context.startService ()
    • The onCreate () service creates a notification icon and registers a broadcast receiver
    • Broadcast Receiver onReceive () checks to see if the state of the network has changed in intent, and then checks if it is connected to a specific SSID, and then calls the special class that I made for registration / authentication.
+5
source share
1

?

. , BraodcastReceiver, , . , onReceive() , Android . , - BroadcastReceiver. , BroadcastReceiver, , .

? ?

. (. )

?

, <intent-filter> <receiver> . BroadcastReceiver , . , . - :

    <receiver
            android:name=".MyReceiver" >
        <intent-filter>
            <action android:name="android.net.wifi.STATE_CHANGE"/>
        </intent-filter>
    </receiver>

startService() ? 1 , , ?

startService() . , . startService() onStartCommand() . , , peekService() BroadcastReceiver. IBinder, , , .

. android.net.wifi.STATE_CHANGE: Wi-Fi

+7

All Articles