AkBaylife
AkBaylife

Reputation: 11

Open and close 3rd party app within my app in android

I know it is impossible to close a running 3rd party app. But what if i opened the 3rd party app within my app? Is there a way to close/finish it?

Upvotes: 1

Views: 1001

Answers (1)

Nitin
Nitin

Reputation: 1986

Yes it is possible but the user should have that app installed on his device. see following links

Open another application from your own (intent)

Launch an application from another application on Android

ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> pids = am.getRunningAppProcesses();
             int processid = 0;
       for(int i = 0; i < pids.size(); i++)
       {
           ActivityManager.RunningAppProcessInfo info = pids.get(i);
           if(info.processName.equalsIgnoreCase("here your package name")){
              processid = info.pid;
           } 
       }
android.os.Process.killProcess(processid);

Hope it will help :)

Upvotes: 2

Related Questions