Android app run notification if user has not opened app

Viewed 45

Im trying to run a notification if a user has not opened an app in say 24 hours to encourage them to open it (Similar to duolingo style). Im using Java and I can set a periodic notification using workmanager but it runs while the app is open which is not what I want. I want the notification to run every 24 hours however if the user has opened the app this timer should reset, I've searched for this but can't find what I require exactly

1 Answers

I would recommend to use AlarmManager for your case. You can, for example, reschedule it in Application.onCreate() method to fire in 24 hours after user last launched an app. First you need to cancel previously scheduled alarm using cancel method, and then set a new alarm to fire in 24 hours using one of the set...() methods available in AlarmManager class.

Related