I have created the start alarm as shown below

 public class MyScheduleReceiver extends BroadcastReceiver {

   // Restart service every 30 secondsprivate static final long REPEAT_TIME = 
1000 * 5;
@Overridepublic void onReceive(Context context, Intent intent) {
  AlarmManager service = (AlarmManager) context
    .getSystemService(Context.ALARM_SERVICE);
 Intent i = new Intent(context, MyStartServiceReceiver.class);
 PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
    PendingIntent.FLAG_CANCEL_CURRENT);Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 5);
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
    cal.getTimeInMillis(), REPEAT_TIME, pending);

I crate this for stop alarm and i call it from main activity.Manifest i 
think is ok...Work repeat but no stop!!!

      public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.setup);

    sendBroadcast(new Intent(this,MyScheduleReceiver.class));
}
public void StopRepeat(View view) {

    sendBroadcast(new Intent(this,MyStopReceiver.class));   
}

 public class MyStartServiceReceiver extends BroadcastReceiver {


 public void onReceive(Context context, Intent intent) {

  Toast.makeText(context, "Repeat service!.",
           Toast.LENGTH_LONG).show();
    }

  public class MyStopReceiver extends BroadcastReceiver {

  // Restart service every 30 seconds
  private static final long REPEAT_TIME = 1000 * 5;

  @Override
  public void onReceive(Context context, Intent intent) {
    AlarmManager service = (AlarmManager) context
        .getSystemService(Context.ALARM_SERVICE);
    Intent istop = new Intent(context, MyStartServiceReceiver.class);
    PendingIntent pending = PendingIntent.getBroadcast(context, 0, istop,
        PendingIntent.FLAG_CANCEL_CURRENT);
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.SECOND, 5);

      service.cancel(pending);

But the service is not stopping. What might be the issue?Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to