12/08/2018, 15:52

How to deal with background execution limits on Android O

As we are expecting about new Android version - Android O, on August 22nd, Google offically launch Android O what we known as Android Oreo, my favorite cookie by the way haha. So, I decided to write this post to discuss about one of the most important change - the background service ...

As we are expecting about new Android version - Android O, on August 22nd, Google offically launch Android O what we known as Android Oreo, my favorite cookie by the way haha. So, I decided to write this post to discuss about one of the most important change - the background service mechanism. Before Oreo, everytime and go to the coffee shop to meet up with some iOS friends, they complain that background job is freaking hard on iOS, I laughed at their faces because of how easy Android background job is. But, every easy things came with their disadvantages, background service is also the biggest problem in Android, which makes the phone drain battery so fcking hard. Now, the time has come, Google made up themselves and force Android developers communities to "serve" the end-users, brings end-user a better experiences. Ok, let's talk about how background things has changed.

App cannot run freely in the background

  • Call start service in background will cause IllegalStateException
    • NO service
    • NO send for pending intent wrapping services
  • When move app from foreground to background -> services SHUTDOWN
  • CANNOT register implicit broadcasts in the manifest. However, following implicit broadcasts are still allowed to register
    • ACTION_LOCKED_BOOT_COMPLETED, ACTION_BOOT_COMPLETED
    • ACTION_USER_INITIALIZE
    • ACTION_LOCALE_CHANGED
    • ACTION_USB_ACCESSORY_ATTACHED, ACTION_USB_ACCESSORY_DETACHED, ACTION_USB_DEVICE_ATTACHED, ACTION_USB_DEVICE_DETACHED
    • ACTION_HEADSET_PLUG
    • ACTION_CONNECTION_STATE_CHANGED, ACTION_CONNECTION_STATE_CHANGED, ACTION_ACL_CONNECTED, ACTION_ACL_DISCONNECTED
    • ACTION_CARRIER_CONFIG_CHANGED
    • LOGIN_ACCOUNTS_CHANGED_ACTION
    • ACTION_PACKAGE_DATA_CLEARED
    • ACTION_PACKAGE_FULLY_REMOVED
    • ACTION_NEW_OUTGOING_CALL
    • ACTION_DEVICE_OWNER_CHANGED
    • ACTION_EVENT_REMINDER
    • ACTION_MEDIA_MOUNTED, ACTION_MEDIA_CHECKING, ACTION_MEDIA_UNMOUNTED, ACTION_MEDIA_EJECT, ACTION_MEDIA_UNMOUNTABLE
    • SMS_RECEIVED_ACTION, WAP_PUSH_RECEIVED_ACTION
  • Location system service computes a new location for your app only a few times each hour

Ops! How can I deal with this             </div>
            
            <div class=

0