我正在做一個應用程序發送經緯度的座標,所以我擴展了一個服務並實現了LocationManager。 這是我的代碼部分:Android:實現LocationManager的最佳實踐
public class LocationServiceTracking extends Service implements LocationListener{
....
@Override
public void onCreate() {
super.onCreate();
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (isGPSEnabled && provider.equals(LocationManager.GPS_PROVIDER)) {
try {
mLocationManager.requestLocationUpdates(3000, 0, criteria, this, null);
Log.d("GPS Enabled", "GPS Enabled");
} catch (SecurityException se) {
se.printStackTrace();
Crashlytics.logException(se);
}
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
}
我的問題是¿會是什麼,如果你這樣做是爲了做到這一點在onCreate()
象現在或將其更改爲onStartCommand()
最好的做法是什麼?