Bhagirath
Bhagirath

Reputation: 161

Terminating the browser programmatically

I'm trying to close/terminate the browser programmatically. But I did not find any method in the default browser Class. Does anyone know how to?

Upvotes: 0

Views: 2562

Answers (2)

N-JOY
N-JOY

Reputation: 7635

Killing prcesses in android is bad idea and it is never encouraged. but if still you want to continue with this you could do something like this.

List<ActivityManager.RunningAppProcessInfo> list = servMng.getRunningAppProcesses();
    if(list != null){
     for(int i=0;i<list.size();++i){
      if("com.android.browser".matches(list.get(i).processName)){
       int pid = android.os.Process.getUidForName("com.android.browser");
             android.os.Process.killProcess(pid);
      }
     }
    }

but also have a look at this answer.

A nice answer, this will give you detailed description of why this method of killing processes is discouraged.

Upvotes: 3

CommonsWare
CommonsWare

Reputation: 1007584

If you are referring to your own use of WebView, just finish() your activity.

If you are referring to some other application, you cannot "close/terminate the browser programmatically", particularly if it is in the foreground.

Upvotes: 1

Related Questions