I usually write this code to start a service with AlarmManager
.
intent = new Intent(getActivity(), someservice.class);
pendingNotificationIntent = PendingIntent.getService(getActivity(), 0, intent, 0);
alarm = (AlarmManager) getActivity().getSystemService(getActivity().ALARM_SERVICE);
int interval = 30 * 1000;
long now = Calendar.getInstance().getTimeInMillis();
alarm.setRepeating(AlarmManager.RTC_WAKEUP, now, interval, pendingNotificationIntent);
My AsyncTask
is a private class where I register AlarmManager
object.
How can I call the AsyncTask
instead of a service using AlarmManager
object?
PS. If there is a better way to run AsyncTask
every X seconds/minutes, please propose it!