我是服务新手,我找不到停止由警报管理器启动的服务的方法。
这是停止服务的代码:
stopservices()
{
CancelAlarm(getApplicationContext());
Intent intent1 = new Intent(this, CrService.class);
stopService(intent1);
}
// method Cancel alarm
public void CancelAlarm(Context context)
{
Intent intent = new Intent(context, ReceiverPositioningAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager AvdhiCralarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AvdhiCralarm.cancel(sender);
sender.cancel();
// stopService(new Intent(this, CrService.class));
}
答案 0 :(得分:0)
stopservices()
{
CancelAlarm(getApplicationContext());
}
// method Cancel alarm
public void CancelAlarm(Context context)
{
Intent intent = new Intent(context, ReceiverPositioningAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager AvdhiCralarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AvdhiCralarm.cancel(sender);
sender.cancel();
// just write your context before call stop service & your name class before this
context.stopService(new Intent(Yourcalss.this, CrService.class));
^ ^
|--------------------------------|
}