android timertask 替代长时间运行的 BackgroundService

android timertask alternative for longrunning BackgroundService

我正在寻找 java.util.TimerTask 的替代方案。

我的应用应该会在一个月内开始随机通知。

TimerTask只能处理一个,之后就不行了。

是否需要从后台服务调用? 或者像 AlarmManager 这样的东西就足够了吗?

您需要使用AlarmManager for scheduling tasks in this time range. There is an official training doc in the Android documentation that you might find interesting: https://developer.android.com/training/scheduling/alarms.html

另一种用于安排较长周期任务的可能性是 JobScheduler,尽管它更适合安排网络作业。