SoulRayder
SoulRayder

Reputation: 5166

Closing an app from my app

I have developed an app which password protects another app ( say app A). So when I try to open app A, an activity pops on top of A prompting the user to enter password. Upon incorrect entry, it should close that activity and also close app A, which is directly under 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 it does not work.

Later I realized that this is probably because the process of app A is not a direct child of my app's process ( that is, my app did not call app A). So is there anyway I can close but not necessarily kill app A from my app? What I mean to say is, killing app A is optional but closing it is mandatory.

Upvotes: 4

Views: 123

Answers (2)

Gopal Gopi
Gopal Gopi

Reputation: 11131

I am not sure how to kill another app process. but you can take the user to home screen upon entering 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)
}

Upvotes: 1

bracken
bracken

Reputation: 374

Maybe this would work:

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

You'll need to add the following permission to your manifest.

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

Upvotes: 1

Related Questions