我想用alarmmanger创建一个服务运行背景(当应用程序不工作时)。 你能帮我解决这个问题吗?
答案 0 :(得分:0)
您可以尝试以下操作:
Intent intent = new Intent(this, Service.class);
pendingIntent = PendingIntent.getService(this, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 10);
alarmManager.setRepeating(
AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(),
1000*10,
pendingIntent);//10s