android - How to kill a foregound service -


I am developing an app that requires the use of the foreground service, but this service works properly I can not kill it First of all, I tried to kill using the stop service, then I saw a topic where people asked to use startService with an extra to kill the service:

In my activity:

  intends = new intent (this, MyService.class); I.putBooleanExtra ("killService", true);  

Start commencement in my service:

  if (intent.getBooleanExtra ("killService", incorrect)) {stopForeground (true); StopSelf (); ....  

When I press the user on a special button of my activity, then I want to stop the service:

  Public Zero onClick (see V) {switch (v.getId) {Case R.id.myButton: (I want to kill service here) break; If your service " binding    

If your service is binding and you have been successfully compelled, then

service through call for bindService (intent, service connection, intestine), You must call unbindService (..) from your tied client.

If your service is binding and both are supported, the hybrid approach to stop you Must use.

  1. Bound service : To prevent the first service, All customers have already been compelled.

  2. Service started : With startService to prevent service from being started, you stopService (intent) There is no need to start with any command.

  3. Mixed (forced and initialized) service : You explicitly stop service (intent) and unbind all clients only when all your clients are unbound from the service and the stop service is called, the service will actually stop.

If you are not sure what kind of service you have, read, the explanation is satisfactory.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -