A
A
Alexey2016-08-05 19:31:36
Android
Alexey, 2016-08-05 19:31:36

Why doesn't the service process stop?

There is an "empty" application, the main activity with the buttons "Start" and "Stop" the service via startService/stopService. The service itself is also "empty", at start it returns START_NOT_STICKY. Runs in a separate process.

public class TestService extends Service {
  @Override
  public void onCreate() {
    super.onCreate();
  }

  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    return START_NOT_STICKY;
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
  }

  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
    return null;
  }
}

<service
    android:name=".TestService"
    android:process=":service"
    android:exported="false">
  </service>

When stopped, as expected, onDestroy is called, but the process continues to live on the monitor, and the memory is not unloaded, some insignificant <0.5% processor activity periodically occurs in it.
Once I studied services and did the same example, and I remember for sure that the process was instantly killed by stopService. Now I don't understand why this behavior. Tested on android 4.4 and 6.0.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2016-08-08
@VDG

I can assume that this is an Empty process: https://developer.android.com/guide/components/pro...
+ the kernel gives the process a time quantum, like everyone else, I think.

C
coden55, 2016-08-06
@coden55

Try

@Override
  public void onDestroy() {
    super.onDestroy();
stopself();
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question