Reputation: 365
I want force stop my app after activity destroyed , i tried to use
Process.KillProcess(Process.MyPid());
the app stop but it still able to force stop it again in Settings>App
I also tried to stop it by this code
ActivityManager am = (ActivityManager)GetSystemService(Context.ActivityService);
am.KillBackgroundProcesses("TurkeyanaCall.TurkeyanaCall");
but i got
An unhandled exception occured.
i want to click this button from my app in anyway
Upvotes: 1
Views: 1353
Reputation: 365
I also used this to kill all process used in app .
First i stopped all services then i kill the app totally from everywhere the code below explain this .
try{
StopService(new Intent(this, typeof(CallService)));
StopService(new Intent(this, typeof(TwilioClientService)));
} catch(Exception ee){ }
ActivityManager am = (ActivityManager)GetSystemService(Context.ActivityService);
am.KillBackgroundProcesses("TurkeyanaCall.TurkeyanaCall");
Android.OS.Process.SendSignal(Android.OS.Process.MyPid(), Signal.Kill);
Upvotes: 0
Reputation: 9084
Unhandled Exception:
Java.Lang.SecurityException: Permission Denial: killBackgroundProcesses() from pid=2440, uid=10554 requires android.permission.KILL_BACKGROUND_PROCESSES
As the document said, KillBackgroundProcesses
:
Have the system immediately kill all background processes associated with the given package. This is the same as the kernel killing those processes to reclaim memory; the system will take care of restarting these processes in the future as needed.
Requires the KILL_BACKGROUND_PROCESSES permission.
You should add the permission :
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
Then you could use it :
ActivityManager am = (ActivityManager)GetSystemService(Context.ActivityService);
am.KillBackgroundProcesses(PackageName);
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
Java.Lang.JavaSystem.Exit(0);
Upvotes: 1