android:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
android:start [2021/03/13 01:36] jmerariandroid:start [2021/05/12 15:21] (current) jmerari
Line 11: Line 11:
 ==== Foreground Service ==== ==== Foreground Service ====
   * Typical use case : Music Player keep playing the sound although UI not active   * Typical use case : Music Player keep playing the sound although UI not active
 +  * The term "Foreground" is about PRIORITY. Android will try its best not to kill this service when system becomes low on resource.
   * There are valid scenarios to promote your app to the foreground: The prerequisites for using a foreground service are that your app is executing a task that is immediate, important (must complete), is perceptible to the user (most often because it was started by the user), and must have a well defined start and finish. If a task in your app meets these criteria, then it can be promoted to the foreground until the task is complete. ... playing music, completing a purchase transaction, high-accuracy location tracking for exercise, and logging sensor data for sleep. The user will initiate all of these activities, they must happen immediately, have an explicit beginning and end, and all can be cancelled by the user at any time.((see [[https://android-developers.googleblog.com/2018/12/effective-foreground-services-on-android_11.html]]))   * There are valid scenarios to promote your app to the foreground: The prerequisites for using a foreground service are that your app is executing a task that is immediate, important (must complete), is perceptible to the user (most often because it was started by the user), and must have a well defined start and finish. If a task in your app meets these criteria, then it can be promoted to the foreground until the task is complete. ... playing music, completing a purchase transaction, high-accuracy location tracking for exercise, and logging sensor data for sleep. The user will initiate all of these activities, they must happen immediately, have an explicit beginning and end, and all can be cancelled by the user at any time.((see [[https://android-developers.googleblog.com/2018/12/effective-foreground-services-on-android_11.html]]))
-  * Although the term is "foreground", it doesn't mean running in the main thread. 
   * Apps that target Android 9 (API level 28) or higher and use foreground services must request the FOREGROUND_SERVICE permission.   * Apps that target Android 9 (API level 28) or higher and use foreground services must request the FOREGROUND_SERVICE permission.
   * If your app targets Android 10 (API level 29) or higher and accesses location information in a foreground service, declare the location foreground service type as an attribute of your <service> component.   * If your app targets Android 10 (API level 29) or higher and accesses location information in a foreground service, declare the location foreground service type as an attribute of your <service> component.
   * If the user has granted the ACCESS_BACKGROUND_LOCATION permission to your app, the service can access location all the time. Otherwise, if the user has granted the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission to your app, the service has access to location only while the app is running in the foreground (also known as "while-in-use access to location").   * If the user has granted the ACCESS_BACKGROUND_LOCATION permission to your app, the service can access location all the time. Otherwise, if the user has granted the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission to your app, the service has access to location only while the app is running in the foreground (also known as "while-in-use access to location").
-  * +
 ==== Background Service ==== ==== Background Service ====
 ==== Bound Service ==== ==== Bound Service ====
Line 22: Line 22:
 A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed. A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed.
  
-==== Reference ==== + 
-[[https://developer.android.com/guide/components/services|Android Developer Guide]]+===== Fragment Lifecycle Event Sequence ===== 
 +  - onAttach 
 +  - onCreate 
 +  - onCreateView 
 +  - onViewCreated 
 +  - onActivityCreated 
 +  - onViewStateRestored 
 +  - onStart 
 +  - onResume 
 +  - onPause 
 +  - onStop 
 +  - onDestroyView 
 +  - onDestroy 
 +  - onDetach 
 + 
 +===== Background Thread ===== 
 +  - [[https://developer.android.com/guide/background/threading?hl=en|Basic practical implement background task with callback]] 
 + 
 +==== References ==== 
 +  - [[https://developer.android.com/guide/components/services|Android Developer Guide]] 
 +  - [[https://android-developers.googleblog.com/2018/12/effective-foreground-services-on-android_11.html]] 
 +  - [[https://proandroiddev.com/deep-dive-into-android-services-4830b8c9a09]]
  • android/start.1615574176.txt.gz
  • Last modified: 2021/03/13 01:36
  • by jmerari