Android App Development All-in-One For Dummies by Burd

Android App Development All-in-One For Dummies by Burd

Author:Burd
Language: eng
Format: epub
ISBN: 9781118973844
Published: 2015-07-27T00:00:00+00:00


In the client app’s activity, press the Stop button.

Hooray! The Service Destroyed message appears on your emulator’s screen.

You can see all the am command’s options by typing adb shell am in the Terminal window.

For more information about the Android Debug Bridge, see Book I, Chapter 2. For more information about broadcast receivers, see Chapter 4 in this minibook.

Starting and Binding

You can do two kinds of things with a service:

You can start and stop a service.

You do this by calling the Context class’s startService and stopService methods. Also, a service can take the bull by the horns and call its own stopSelf or stopSelfResult method.

When you call startService, you create only a momentary relationship with the service. Android creates an instance of the service if no instances are already running. In addition, Android calls the service’s onStartCommand method. (See Listing 3-1.)

Calls to startService don’t pile up. To illustrate the point, consider this sequence of method calls, along with their resulting Android responses:

Activity A calls startService to start MyService.

Android instantiates MyService and

calls the instance’s onStartCommand method.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.