Replacing Services With Jobs in Android Oreo 8.0

JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai
edited November 27 in Xamarin Blog

Have you used the JobScheduler API yet?

If you haven't, read our blog for a quick primer on JobScheduler and let us know what you think!

Feel free to discuss this post below.

Posts

  • andrekibaandrekiba ITUniversity ✭✭

    Is there any possibility to use JobScheduler in Android 7.1? Now I'm using GcmTaskService

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    @andrekiba You can use JobScheduler with Android Lollipop 5.0 (API 21) and above! Given that Android Oreo has changed background limits it's a great time to swap over now!

  • XeviousXevious BRMember

    Let me share my experience as a government developer. I work with enterprise applications. It´s a much more restricted market than the market for end users.

    And what I see is that Google/Android only target the end users market, giving no attention at all at the enterprise market. Each Android new version is restricting the enterprises apps like this new subject about services and an obsession with saving batteries.

    In one example, we developed an application that allows technicians from a customer of us, a basic sanitation company, to run service orders on tablets. And there is the possibility of urgent service order (leaks in the water network, for example) be downloaded in some tablet, controlled by a big back-end application . To meet these requirements, you need a background service, based on pulling the server all time, running from minute to minute to listen for urgent service orders. When we developed this mobile app, one of or customer requirements is that tablet battery is a thing not about to care (they use the equipment connected in the car usb charge, all time).

    And we now see this aggressive, and confusing stance of Google in Android over saving batteries and applications performance. It takes us with the will to abandon this Android market and go back to Windows again (in laptops). At last, in Windows the API is much more constant and has much more reliability.

    Just our cents.

    Enterprise developers.

  • EricBrunnerEricBrunner USMember ✭✭

    @Xevious I guess there is some missunderstanding about the Google restrictions. Take a look here about DOZE mode

    https://developer.android.com/training/monitoring-device-state/doze-standby.html

    and when DOZE mode applies. When your client phones are all connection to the power plug you never have to worry about those battery optimization features because DOZE mode never happens when connected to the charger.

    I guess on some newer phones there is a battery optimization opt-out under your settings , where you can configure each app. but I don't know excatly.

  • MSiccDevMSiccDev CHMember ✭✭

    While I was able to create a scheduled job service for Android O, it does not seem to run on lower version of Android if I follow the blog post. Problem is that the entry for the service in the AndroidManifest seems to be malformatted (at least this is what I get when I try to let the App run on a Galaxy A3 (2016) with Nougat installed... Any ideas on how to fix that are welcome...

  • EricBrunnerEricBrunner USMember ✭✭

    I guess the blog i removed. When I navigate here: https://blog.xamarin.com/replacing-services-with-jobs-in-android-oreo-8-0/

    I only get a "No posts here…".

  • MSiccDevMSiccDev CHMember ✭✭

    @EricBrunner said:
    I guess the blog i removed. When I navigate here: https://blog.xamarin.com/replacing-services-with-jobs-in-android-oreo-8-0/

    I only get a "No posts here…".

    try this one: https://blog.xamarin.com/replacing-services-jobs-android-oreo-8-0/

  • MSiccDevMSiccDev CHMember ✭✭

    @MSiccDev said:
    While I was able to create a scheduled job service for Android O, it does not seem to run on lower version of Android if I follow the blog post. Problem is that the entry for the service in the AndroidManifest seems to be malformatted (at least this is what I get when I try to let the App run on a Galaxy A3 (2016) with Nougat installed... Any ideas on how to fix that are welcome...

    Leaving this here if anyone else ever gets to this point. The solution to get the correct service name entry in AndroidManifest is to NOT give the JobService a name. This way, it will be matched during build with a valid name for all OS Version that support it in the final AndroidManifest.

  • EricBrunnerEricBrunner USMember ✭✭
    edited December 7

    @MSiccDev Did you have that issue with the provided sample from the blog post

    https://github.com/topgenorth/xamarin.android-jobschedulersample

    on Android < 8.x (API-LEVEL 26)?
    Thanks for sharing your experience.

  • MSiccDevMSiccDev CHMember ✭✭
    edited December 7

    @EricBrunner I haven't tested the sample itself, but I followed the sample to create my own job. The problem is that on API levels below 26, every service registration must be lower-case. The implementation of the sample creates the name exactly like in the Attribute, which causes the error. If you do not register the name manually, the base class gets wrapped with a hash and registered with [hash].ServiceName, which does the trick for being compatible with lower levels. I tested it in the meantime with another Android Nougat device without any problems.

    See also this sample log entry from my service:
    12-07 09:46:42.232 LGE Nexus 5X Debug 12809 WU_Droid Successfully scheduled md57b091714957b498671bcc068059a014b.NewPostsJob

Sign In or Register to comment.