Why no Service.onStop method?

I’ve read a lot around Android service. As I understand, the lifecycle is:

void onCreate() 
    void onStart(Intent intent) 
    ...
void onDestroy()

http://www.linuxtopia.org/online_books/android/devguide/guide/topics/fundamentals.html

  • Tapping form field in WebView does not show soft keyboard
  • Forcing Android to use RTSP/AVP/TCP interleaved
  • Get Bluetooth local mac address in Marshmallow
  • Icon selector not working with PagerSlidingTabStrips
  • How to specify an RGB-format color using XML on Android
  • Android studio error: An error occurred while trying to compute required packages
  • But there’s is no onStop method.
    Questions:

    • Why isn’t there a stop method?
    • What happens when a stopService request is made on my Service? (from outside, perhaps by Android itself). Can I detect this event?
    • I’d like to enforce (or at least verify) that my service is a singleton within a process. How can I do this (or does Android enforce this behind the scenes)?

    For context, I have some resources I’d like to allocate and release while the service is running (in a “started”), and another set of resources I’d like to allocate and release while the service is a “created” state.

    Related posts:

    How to share a single library source across multiple projects
    Start Activity Using Custom Action
    How to make a tutorial for my android application?
    How to detect shake event with android?
    How to include a proguard configuration in my Android library (AAR)
    How to provide content for Intent.ACTION_GET_CONTENT
  • Android MediaPlayer Stop and Play
  • Eclipse is trying to build the files in my .svn directories… how can I tell it to stop?
  • Tools.jar is not in Android Studio classpath
  • Captive portal with android hotspot programmatically configured
  • How to use ant to build with android
  • How to show the PopupWindow alway above the button(view)?
  • One Solution collect form web for “Why no Service.onStop method?”

    As I understand, the lifecycle is:

    onStart() has been deprecated for a few years. onStartCommand() is the current lifecycle method.

    Why isn’t there a stop method?

    Because there is no need for one.

    What happens when a stopService request is made on my Service?

    You will be called with onDestroy().

    Can I detect this event?

    You can override onDestroy().

    I’d like to enforce (or at least verify) that my service is a singleton within a process. How can I do this (or does Android enforce this behind the scenes)?

    Services are natural singletons. There will be 0 or 1 instance of your service at any given time.

    For context, I have some resources I’d like to allocate and release while the service is running (in a “started”), and another set of resources I’d like to allocate and release while the service is a “created” state.

    The “created” state is used both with the command pattern (startService() and onStartCommand()) and the binding pattern (bindService() and onBind()). Hence, if you call startService(), your service will be purely in the “created” state for hopefully less than a millisecond.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.