在我的应用程序中我使用commonsware库基于警报设置获取地理位置,事情工作正常,但是当我按下后退按钮时,那时我想停止该警报并且不想获取地理位置。
我该怎么做?下面是我用于根据警报获取位置的代码。
private PendingIntent pendingIntent =null;
private AlarmManager alarmManager =null;
private void initLocationTracker()
{
try{
mgr=(AlarmManager)getSystemService(ALARM_SERVICE);
Intent i=new Intent(this, LocationPoller.class);
i.putExtra(LocationPoller.EXTRA_INTENT,
new Intent(this, LocationReceiver.class));
i.putExtra(LocationPoller.EXTRA_PROVIDER,
LocationManager.GPS_PROVIDER);
pi=PendingIntent.getBroadcast(this, 0, i, 0);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime(),
PERIOD,
pi);
Toast
.makeText(this,
"Location polling every 30 minutes begun",
Toast.LENGTH_LONG)
.show();
}
catch (Exception e)
{
String s = e.getMessage();
}
}