前段时间,由于公司项目中某个功能需要用到轮询的操作,所以参考了网上的一些资料,做了一个demo。主要方案是:AlarmManager + BroadcastReceiver + Service
首选需要获取AlarmManager,并包装要执行的服务:
/**
* 开始轮询
*/
public static void startPolling(Context context, int seconds, Class<?> cls, String action) {