question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exact scheduling of Jobs doesn't work when App is killed for long time (>1 min) on One Plus 5T(Nougat)

See original GitHub issue

I am trying to show a notification once a day at exact time. The time is coming from backend API. Below code is working fine when app is in foreground or background. But when app is killed for long time (~1min) or after reboot I am not getting notification on One Plus 5T(Nougat) and also on Oppo device(Mashmallow). Also, sometimes when I relaunch the app, I get all the failed notifications at once. Everything’s working fine on Asus Zenfone Max (Mashmallow). Alarms are triggering in every scenario in Asus (foreground, background, screen locked or even reboot)

Below is adb log for One Plus 5T

//when app is killed and before alarm scheduled time 
Shikhars-MacBook-Pro:HOGAndroid_New shikhardeep$ adb shell dumpsys alarm | grep "com.tf.eros.faythTv"
    ELAPSED_WAKEUP #0: Alarm{3a8c0ae type 2 when 1118303576 com.tf.eros.faythTv}
      tag=*walarm*:com.tf.eros.faythTv/com.evernote.android.job.v14.PlatformAlarmReceiver
      operation=PendingIntent{e233e4f: PendingIntentRecord{217c9dc com.tf.eros.faythTv broadcastIntent}}
    ELAPSED_WAKEUP #0: Alarm{44439ba type 2 when 1118303589 com.tf.eros.faythTv}
      tag=*walarm*:com.tf.eros.faythTv/com.evernote.android.job.v14.PlatformAlarmReceiver
      operation=PendingIntent{a7f706b: PendingIntentRecord{a45a7c8 com.tf.eros.faythTv broadcastIntent}}
  u0a355:com.tf.eros.faythTv +1s718ms running, 4 wakeups:
      *walarm*:com.tf.eros.faythTv/com.evernote.android.job.v14.PlatformAlarmReceiver

//when app is killed and just after the alarm scheduled time
Shikhars-MacBook-Pro:HOGAndroid_New shikhardeep$ adb shell dumpsys alarm | grep "com.tf.eros.faythTv"
  u0a355:com.tf.eros.faythTv +1s722ms running, 6 wakeups:
      *walarm*:com.tf.eros.faythTv/com.evernote.android.job.v14.PlatformAlarmReceiver

Code

public class ShowHoroscopeNotificationJob extends Job {

    public static final String TAG = "HOROSCOPE_NOTIFICATION";

    public ShowHoroscopeNotificationJob() {
        super();
    }

    @Override
    protected void onReschedule(int newJobId) {
        super.onReschedule(newJobId);
    }

    @NonNull
    @Override
    protected Result onRunJob(@NonNull Params params) {
        try {

            NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(getContext(), "HOG_NOTIFICATION")
                            .setSmallIcon(R.drawable.notification_icon)
                            .setLargeIcon(BitmapFactory.decodeResource(getContext().getResources(), R.mipmap.ic_launcher))
                            .setColor(ContextCompat.getColor(getContext(), R.color.colorPrimary))
                            .setContentTitle("Horoscope Reminder")
                            .setContentText("Check out Daily Horoscope !!!")
                            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                            .setAutoCancel(true);

            NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);

            if (notificationManager != null) {
                notificationManager.notify(new Random().nextInt(40) + 1, mBuilder.build()); 
                schedule(getExactTime(ZPreferences.getHoroscopeReminderTime(getContext()))); //again calling schedule() as setExact() can't be periodic 
                return Result.SUCCESS;
           }

        } catch (Exception e) {

            e.printStackTrace();
            return Result.RESCHEDULE;
        }
    }

    public static void schedule(long exactInMs) {

        if (exactInMs != 0L) {

            new JobRequest.Builder(ShowHoroscopeNotificationJob.TAG)
                    .setExact(exactInMs)
                    .build()
                    .schedule();
        }

    }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
Noble-Mushtakcommented, Apr 22, 2018

I just read this article about AlarmManager and they said the solution to this problem was to put the android:process=":remote" attribute in the <receiver> element for the BroadcastReceiver class setup for use by the AlarmManager. However, in this library, we use Jobs, so we can’t just edit the manifest for the BroadcastReceiver like this. Is there any equivalent to android:process=":remote" in the Evernote library? If you haven’t already done it, is there anyway to integrate this attribute into your library?

0reactions
vRallevcommented, Jan 19, 2018

Thanks for the update, that info will be helpful in the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exact Job scheduling doesn't work when App is killed for long ...
Exact Job scheduling doesn't work when App is killed for long time (>1 min) on One Plus 5T(Nougat) · Ask Question.
Read more >
OnePlus 5t doesn't kill apps while reboot
To check running apps.Go to: Settings > developer options > running servicesThere, you can see all the apps that are currently working.Some apps...
Read more >
Caches Explained - OnePlus Community
First, a cache (pronounced like "cash") is a temporary storage area that is faster than a longer-term storage area. The first time you...
Read more >
Background apps getting killed automatically
Hi,From past 3-4 days, I started to notice that the background apps are getting killed automatically. Is this something isolated or is it...
Read more >
very low call volume issue - OnePlus Community
It's very difficult to hear other person voice. yes when i bought OP3 hearing sound on call was good but after updating to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found