如何重复警报管理器在30分钟内运行一次活动? 如何在30分钟内完成一次这项主要活动,任何人都可以解释一下
代码:
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
答案 0 :(得分:1)
private void setLocationSendingAlarm() {
AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(), GoogleMapService.class);
intent.putExtra("locationSendingAlarm", true);
PendingIntent pendingIntent = PendingIntent.getService(this, 987654321, intent,0);
try {
alarmManager.cancel(pendingIntent);
} catch (Exception e) {
}
int timeForAlarm=60000;
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+50000, timeForAlarm, pendingIntent);
}
答案 1 :(得分:0)
请参阅AlarmManager.setRepeating方法。你可以查看example