Search code examples
androidscheduled-taskssamsung-mobile

Issue in SM-G950F(Samsung s8) for running OneoffTask


I am facing an issue, where my app users cannot get past a point.

When the user tries to login, it gets logged in, but after that I hit an API with "OneoffTask" using this code :

OneoffTask task = new OneoffTask.Builder()
        .setService(SyncService.class)
        .setTag(TaskConstants.UPLOAD_STREAK)
        .setExecutionWindow(0L, 200)
        .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
        .setPersisted(true)
        .setUpdateCurrent(true)
        .build();

GcmNetworkManager mGcmNetworkManager = GcmNetworkManager.getInstance(MainApplication.getContext());
mGcmNetworkManager.schedule(task);

This code is executed, but the scheduled task does not execute. samsung s8 model : SM-G950F. It is working on all other devices. Why is this issue, I am also not getting an error. It is just stuck there.


Solution

  • I'm not able to comment, so I have made some assumptions regarding the issue you are facing and hopefully have this right. Please let me know if that is not the case.

    The Samsung S8 is probably upgraded to Android 8.0 (Oreo), right?

    In Oreo there are limitations that you need to handle in a different manner.

    Android 8.0 places limitations on what apps can do while users aren't directly interacting with them. Apps are restricted in two ways "Background Service Limitations" and "Broadcast Limitations", reference: https://developer.android.com/about/versions/oreo/background#overview

    Also the GcmNetworkManager require that the user have "play services" installed, you have to ensure to check that. GCM is also soon deprecated so look for other solutions, replaced by FCM for instance: https://developers.google.com/cloud-messaging/android/client (see also requirements to ensure the S8 meets them).

    To ensure that GcmNetworkManager scheduler works as espected you need to combine it with a JobScheduler. Best reference I found is this: https://github.com/yigit/android-priority-jobqueue/wiki/Integration-with-JobScheduler-and-GcmNetworkManager

    My experience with JobScheduler is that it is working great on all newer devices I have tested (Android 6.0 --> 8.0) so hopefully you don't need so much "Oreo-logic".

    Please let me know if that got you in the right direction :)