I found that extra functions are not passed with intent when stopService is called. As a workaround, just call startService (Intent) and stopService (Intent) immediately after each other.
Example code from action:
Intent j = new Intent(SocketToYa.this, AccelerometerDataSocket.class); j.putExtra("com.christophergrabowski.sockettoya.DestroyService", true); startService(j); stopService(j);
In Service.onStartCommand,
intent.hasExtra("com.christophergrabowski.sockettoya.DestroyService")
will evaluate to true, and you will destroy your service as provided by the API (i.e. by calling stopService, which in turn will call OnDestroy after calling onStartCommand).
source share