Open an Url within an Activity


I have the following question: How to Open an Url in an Activity.

This activity is my Activity_ Main, in it I have an image of a cardview with Url, but when I click it opens the browser options, but what I want is for these links to be opened within my application.

"I've searched for tutorials but everyone talks about WebView" the truth is that I do not want a web view inside my activity_main. I have an AcivityWeb that works well for other uses like going to my website from a FAB, but it's not the Main.

Important! These links come from the firebase.

asked by Elihat Caceres 04.01.2017 в 20:18

2 answers


Use WebViewClient , and within the method shouldOverrideUrlLoading() loads in the same view the url, this way when clicking on a link will be forced to load within the WebView . :

WebView webView = (WebView)findViewById(;
webView.setWebViewClient((new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //Al dar clic en un link se obligará a cargar dentro del WebView.
            return true;

We load the page within WebView .

By clicking on a link, it will open within the same WebView .

answered by 04.01.2017 в 21:06

You must use the WebViewClient to not leave the application. I'm not sure this is what you need.

    WebView appWeb = (WebView) this.findViewById(;
    //Habilitamos el javaScript y el zoom
    //Cargamos el enlace definido
    //Este método es para que el navegador se quede en nuestra aplicación
    appWeb.setWebViewClient(new WebViewClient(){
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
       return false;
answered by 04.01.2017 в 20:55