私のアプリケーションでは、コモンズウェア ライブラリを使用してアラーム設定に基づいて地理的位置を取得していますが、うまく機能していますが、[戻る] ボタンを押したときにそのアラームを停止し、地理的位置を取得したくありません。
これどうやってするの。以下は、アラームに基づいて場所を取得するために使用しているコードです。
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();
}
}