在我的应用程序中,我正在使用 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();
}
}