3

I have an app which plays music from a local server and opens music player in the web browser but when the user goes back to the Home activity and launches Another activity which plays a video on the browser, The video opens in a different tab of the browser, while music tab does not get closed.

Can I close an already opened browser tab when another tab opens? If not. Please suggest some workarounds.

Rob
  • 4,927
  • 12
  • 49
  • 54
MR. Kumar
  • 661
  • 8
  • 25

3 Answers3

4

You can't control another applications life-cycle . so you can't close tabs that are running in the browser.

what you can do on the other hand is to use WebView to open the audio/video then you have full control over it (what and when) to load/close content.

Mr.Me
  • 9,192
  • 5
  • 39
  • 51
3

After lots of struglling ,i reached on conclusion,we cant handle the operation of other application without permission by owner of application,so i have found alternet solution using webview now its working.

MR. Kumar
  • 661
  • 8
  • 25
0

it isn;t the good way to do so, if you are interested in this then the code would be 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);
  }
 }
}
nixxo_raa
  • 391
  • 8
  • 21