如何安排在android中运行的服务

Mer*_*ero 2 android android-service

我在我的应用程序中有一个服务,它提出了一些API请求并使用响应中提供的数据,有没有办法安排服务在每小时运行谢谢

Mer*_*ero 6

这就是我最后的表现:

Calendar cal = Calendar.getInstance();
Intent intent = new Intent(this, ProximityAlertService.class);
PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Log.d("Main",String.valueOf( cal.getTimeInMillis()));
//make the alarm goes off every 10 sec (not exact help to save battery life)
alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 10000, pintent);
Run Code Online (Sandbox Code Playgroud)