i have made a service in my project and i want to start the start after every 2mins. i am using the folowing code but its not working properly.
public class ScheduleSync extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent)
{
AlarmManager service = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, StartMyServiceReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(), 60000*2, pending);
}
}
public class StartMyServiceReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "receive broadcast", Toast.LENGTH_LONG).show();
Log.d("StartMyServiceReceiver", "receive broadcast");
Intent service = new Intent(context, myservice.class);
context.startService(service);
}
}
kindly help me regarding this issue. when i see the taskmanager myservice is running at backend.