Reputation:
How to repeat an alarm manager to run my activity once in 30 minutes? How to simply run this main activity once in 30 minutes can anybody explain me pls
code :
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);
}
}
Upvotes: 0
Views: 126
Reputation: 2370
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);
}
Upvotes: 1
Reputation: 54732
see AlarmManager.setRepeating method. you can check this example
Upvotes: 0