Use onStart for compatibility (fix #32)
Этот коммит содержится в:
@@ -34,6 +34,8 @@ public class PositionProvider {
|
|||||||
public interface PositionListener {
|
public interface PositionListener {
|
||||||
public void onPositionUpdate(Location location);
|
public void onPositionUpdate(Location location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
private final LocationManager locationManager;
|
private final LocationManager locationManager;
|
||||||
@@ -44,7 +46,8 @@ public class PositionProvider {
|
|||||||
private boolean useCoarse;
|
private boolean useCoarse;
|
||||||
|
|
||||||
public PositionProvider(Context context, String type, long period, PositionListener listener) {
|
public PositionProvider(Context context, String type, long period, PositionListener listener) {
|
||||||
handler = new Handler(context.getMainLooper());
|
this.context = context;
|
||||||
|
handler = new Handler(this.context.getMainLooper());
|
||||||
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
this.period = period;
|
this.period = period;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
@@ -80,7 +83,7 @@ public class PositionProvider {
|
|||||||
|
|
||||||
private boolean tryProvider(String provider) {
|
private boolean tryProvider(String provider) {
|
||||||
Location location = locationManager.getLastKnownLocation(provider);
|
Location location = locationManager.getLastKnownLocation(provider);
|
||||||
|
|
||||||
if (location != null && new Date().getTime() - location.getTime() <= period + PERIOD_DELTA) {
|
if (location != null && new Date().getTime() - location.getTime() <= period + PERIOD_DELTA) {
|
||||||
listener.onPositionUpdate(location);
|
listener.onPositionUpdate(location);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -45,9 +45,8 @@ public class TraccarService extends Service {
|
|||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
StatusActivity.addMessage(getString(R.string.status_service_create));
|
StatusActivity.addMessage(getString(R.string.status_service_create));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void onStart(Intent intent, int startId) {
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
||||||
StatusActivity.addMessage(getString(R.string.status_service_start));
|
StatusActivity.addMessage(getString(R.string.status_service_start));
|
||||||
|
|
||||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
@@ -69,7 +68,11 @@ public class TraccarService extends Service {
|
|||||||
positionProvider.startUpdates();
|
positionProvider.startUpdates();
|
||||||
|
|
||||||
sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceChangeListener);
|
sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceChangeListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
onStart(intent, startId);
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user