ورود

View Full Version : نحوه غیر فعال کردن Alarm Manager



#root#
پنج شنبه 24 بهمن 1392, 11:00 صبح
سلام

من الان یه شی از alarm manager ایجاد کردم ، خب دوتا هم هشدار متفاوت با همین شی تنظیم کردم ، اگه بخوام یکی رو کنسل کنم راهی هست؟ یا باید برای هر کاری یه شی جدید ایجاد و در صورت نیاز همونو کنسل کنم؟

public class MyService extends Service {


private AlarmManager am;

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

Notify1();
Notify2();

return super.onStartCommand(intent, flags, startId);
}



private void Notify1() {

Calendar cal = A.getTodayAt(11, 30);
Intent i = new Intent(this, Reciver.class);
i.setAction("ir.training.me.first");
PendingIntent pi = PendingIntent.getBroadcast(this, 1, i, 0);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pi);
}
}

private void Notify2() {

Calendar cal = A.getTodayAt(12, 00);
Intent i = new Intent(this, Reciver.class);
i.setAction("ir.training.me.second");
PendingIntent pi = PendingIntent.getBroadcast(this, 1, i, 0);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pi);
}

}

}

سوال دوم : توی متد getBroadcast نقش آخرین پارامتر ورودی چیه؟

safir187
شنبه 26 بهمن 1392, 20:09 عصر
همون PendingIntent ی که میخای آلارمش رو برداری دوباره با همون requestCode میسازی و از
am.cancel(pendingIntent); استفاده میکنی.