0

如何重复警报管理器以在 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);

    }

}
4

2 回答 2

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);
}   
于 2013-05-04T06:02:23.267 回答
0

请参阅AlarmManager.setRepeating方法。你可以检查这个例子

于 2013-05-04T06:00:23.390 回答