-4

我想用警报管理器创建一个服务运行背景(当应用程序不工作时也是如此)。你能帮我解决这个问题吗?

4

1 回答 1

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
于 2012-08-08T01:53:28.057 回答