Instead, you can use the Broadcast receiver to use as a service. And it can be called the same as the Service with the alarm manager. Recipient:
public class CallListReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Call List receiver called", Toast.LENGTH_LONG) .show(); } }
You can continuously call using:
public void startAlert(Context context) { Intent call_intent = new Intent(this, CallListReceiver.class); PendingIntent pendingCallIntent = PendingIntent.getBroadcast(context, 0, call_intent, 0); AlarmManager call_alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); call_alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (7 * 1000), pendingCallIntent); }
source share