Skip to content Skip to sidebar Skip to footer

Stop Or Kill A Service

I am developing a task manager application.. In that app, I display to the user a list of running apps and kill button beside each app. When user presses kill button the correspond

Solution 1:

I finally found an answer to my question...

After using

activitymanager.killbackgroundprocesses(packageName) , 

we have to check if there are any services running under that package name or process name.

Then we have to use

stopService(new Intent().setComponent(serviceInfos.get(i).service))

But it would return an error because android does not allow us to stop another service

So I used these two lines in the manifest and then ran my app in the build machine

coreApp="true"android:sharedUserId="android.uid.system"

These two lines are there in the android settings manifest file, which allows settings to stop service if the user wants.

So the activity got killed along with the service... :)

And remember this worked only on the build machine....

Solution 2:

Try To Use this permission in your android Manifest File.

<uses-permissionandroid:name="android.permission.KILL_BACKGROUND_PROCESSES" />

and Look at this link it may be helpfull... http://developer.android.com/reference/android/content/Context.html#startService%28android.content.Intent%29

and this: Start a service on onClick

Post a Comment for "Stop Or Kill A Service"