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?
            Asked
            
        
        
            Active
            
        
            Viewed 2,462 times
        
    0
            
            
        - 
                    Browser extends webview. What you wants to do you wants to close browser application? – Krishnakant Dalal May 01 '12 at 12:34
 - 
                    I'm trying to open and close the default browser with the help of my code(using an activity class) – Bhagirath May 03 '12 at 04:15
 - 
                    You can call intent and let the user choose on which browser he wants to surf. – Krishnakant Dalal May 03 '12 at 04:19
 
2 Answers
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.
- 
                    2Note 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
        
- 986,068
 - 189
 - 2,389
 - 2,491