0
我在android中創建了一項約3分鐘後定期調用的服務 服務成功啓動但我無法停止它:S 我已經編寫了啓動和停止服務的這些代碼,anyoe可以幫助我爲什麼停止功能不會停止服務。在Android中停止定期服務
public void startService()
{`enter code here`
//////////for location
Intent myIntent = new Intent(Close_Bus.this, gps.class);
PendingIntent pendingIntent = PendingIntent.getService(Close_Bus.this, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
// 3 miniutes
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), 180000, pendingIntent);
}
public void stopService()
{
//delete();
Intent intent = new Intent(Close_Bus.this, gps.class);
stopService(intent);
}