How to debug a service on Android? does not start Service

1

What I want is to debugge my background service from my android application, but it never runs and I do not know what is due.

This is in the manifest

  <service android:name=".utils.MyService" android:enabled="true"></service>

This is the oncreate of the service

public void onCreate()
{
    android.os.Debug.isDebuggerConnected();
    android.os.Debug.isDebuggerConnected();
    Log.e(TAG, "onCreate");
    initializeLocationManager();
    try {
        mLocationManager.requestLocationUpdates(
                LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
                mLocationListeners[1]);
    } catch (java.lang.SecurityException ex) {
        Log.i(TAG, "fail to request location update, ignore", ex);
    } catch (IllegalArgumentException ex) {
        Log.d(TAG, "network provider does not exist, " + ex.getMessage());
    }
    try {
        mLocationManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
                mLocationListeners[0]);
    } catch (java.lang.SecurityException ex) {
        Log.i(TAG, "fail to request location update, ignore", ex);
    } catch (IllegalArgumentException ex) {
        Log.d(TAG, "gps provider does not exist " + ex.getMessage());
    }
}

Never stop at any instruction in my service method

    
asked by David 31.10.2017 в 01:16
source

1 answer

2

You can perform debugging in the process that your service performs, you can even use the LogCat to print values during the execution of the same.

In the case of the exception, it is preferable to obtain the error message using the getMessage() method:

 Log.i(TAG, "fail to request location update, ignore", ex.getMessage());

Regarding the main problem, registering your service within your AndroidManifest.xml is not enough to start a service when you run your application, for this it has to be started with a Intent , example:

Intent myService = new Intent(MainActivity.this, MyService.class);
startService(myService);
    
answered by 31.10.2017 / 01:32
source