Closing an application from my application

I developed an application in which a password protects another application (say, application A). Therefore, when I try to open application A, a message appears on the screen stating that the user is entering a password. If the recording is incorrect, it should close this activity and also close application A , which is directly below it .

Now I tried to do this using this code:

List<ActivityManager.RunningAppProcessInfo> pids = Unlock.am.getRunningAppProcesses();
                   for(int i = 0; i < pids.size(); i++)
                   {
                       ActivityManager.RunningAppProcessInfo info = pids.get(i);
                       if(info.processName.equalsIgnoreCase("com.A")){
                          pid = info.pid;
                          break;
                       } 
                   }
                android.os.Process.killProcess(pid);

But that will not work.

Later I realized that this was probably due to the fact that the application A process is not a direct child of my application (that is, my application did not call application A). So I can close, but not have to kill app A from my app? I want to say that killing application A is optional, but closing is mandatory .

+4
source share
2 answers

I am not sure how to kill another application process. but you can bring the user to the main screen if you enter the wrong password ...

private void launchHomeScreen() {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    startActivity(intent);
    finish(); // finish our Activity (based on your requirement)
}
+1
source

Maybe this will work:

ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
activityManager.killBackgroundProcesses("com.A");

You will need to add the following permission to your manifest.

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

All Articles