Notify inactive users (who have not opened the app for 7 days) even if Android app gets killed or runs in background

时间秒杀一切 提交于 2020-08-26 13:34:21

问题


I have a requirement where I need to notify inactive users (who have not opened the app for 7 days). This means the notification must be sent if the app is in background for 7 days or the app has been killed and not used for 7 days.

I followed an algorithm using AlarmManager similar to this answer but the notifications are not sent if the app gets killed. I tried to integrate BroadcastReceiver as shown below but it creates an infinite loop when I call it from OnDestroy() of CheckRecentRunclass (because it destroys itself periodically). Also, as I learnt from this answer, onDestroy() does not always get called when app is killed.

public class TimerRestarterBroadcastReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TimerRestarterBroadcastReceiver.class.getSimpleName(), "Service has stopped");
    context.startService(new Intent(context, CheckRecentRun.class));
}
}

Is there any simpler and effective way to do this?


回答1:


Possible scenario using WorkManager:

  • You create a task that send notification in 7 days
  • Every time user uses app change time of the old task to a new one after 7 days



回答2:


You can try workmanager schedule work . I hope this will solve your problem . To know more please check it. Check it



来源:https://stackoverflow.com/questions/62977846/notify-inactive-users-who-have-not-opened-the-app-for-7-days-even-if-android-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!