I have implemented BottomBar
with 5 Fragments
where I have in one of them a WebView
with the Youtube page . The problem is that when I play a video and change from Fragment
to BottomBar
it is still heard, and it should stop.
I have tried with the method onPause
, but nothing. The method onStop
, I don't know why the application stops. Which one should be used in this case?
public class Four_fragment extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.four_tab, container, false);
String url = "https://www.youtube.com/";
WebView appWeb = (WebView) v.findViewById(R.id.webView);
//Habilitamos el javaScript y el zoom
appWeb.getSettings().setJavaScriptEnabled(true);
appWeb.getSettings().setBuiltInZoomControls(true);
//Cargamos el enlace definido
appWeb.loadUrl(url);
//Este método es para que el navegador se quede en nuestra aplicación
appWeb.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
return v;
}
}
Since you have indicated that you are using a
Webview
I had the same problem the other day and I paused it by referencing theonPause
yonResume
delWebView
method inside theonPause
yonResume
del methodFragment
. Something like that:Another solution that I saw on the Internet but that seems a bit more like a workaround than a solution would be to load an empty url in the Webview: