0

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?

Bhagirath
  • 161
  • 2
  • 12

2 Answers2

3

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.

Community
  • 1
  • 1
N-JOY
  • 10,252
  • 7
  • 50
  • 69
  • 2
    Note that this will not work, as is clearly indicated by [the documentation for `killProcess()`](http://goo.gl/vP7kA). This would only work if `com.android.browser` is killing itself, or if the killer is part of the system firmware and runs as the same user account as does `com.android.browser`. – CommonsWare May 01 '12 at 12:58
  • +1 ohhkk my bad. "the kernel will still impose standard restrictions on which PIDs you are actually able to kill" – N-JOY May 01 '12 at 13:02
1

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.

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367