[fixed] Android Webview not Stopping after user presses back Button

Android WebView Jyadatar Use hota hai, Aur Sath me Iske Bahut Sare Problem Samne Aate hai. Jaisa ki Title se Clear Ho Gaya hoga ki, Kis Problem ke Bare me ye Post hai. Ye Post WebView par Addharit hai.

Jaise ki Hum Koi Webview Aaplication Banate hai. Jiska Upyog hum Kisi bhi URL Ko Aapne App Me Load Karne me Karte hai.

Example : Humne Youtube ki Website ka Link Use Kiya. Aur Hum Aapne App me Youtube Access Kar Rahe. Jaise Humne Koi Video Play Kiya.. Aur Kuch Samay Tak Video Dekhe Uske Baad Hum Back Button Press karke Use Activity se Old Acivity me Aa Gaye Tab Bhi Video Play Rahata hai.

App band Karne ke Baad Bhi Video Play Rahta hai. Ya Koi Download Page ko Open Karke Activity Ko Off Kar De Fir Bhi Download Ho Jata hai.

Is Problem Ko Fix Karne Ke Liye Aap In Method Ka Use Kar Sakte hai.

01. Method 1  (onPause, onResume, onDestroy)

@Override
public void onPause() {
    myWebView.onPause();
    myWebView.pauseTimers();
    super.onPause();
} 
@Override 
public void onResume() { 
super.onResume(); 
myWebView.resumeTimers(); 
myWebView.onResume(); 

} 
@Override 
protected void onDestroy() { 
myWebView.destroy(); 
myWebView = null; 
super.onDestroy(); 
}

02. Method 2 

You can do it using the method onPause() of your Activity :

@override
public void onPause() {
    super.onPause();
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        webview.onPause();
    }
}

adding a validation for use in API >= 11 (Honeycomb)

03. Method 3

You should call:

webView.loadUrl("about:blank");

It will destroy all audio/video as well as Javasript objects and stop all running functions on webview

Agar Inme se Agar Koi Bhi Code Work Nahi Karta hai, Ya Aapke Pass Koi Other Solution Hai Plz Comment Se Bataye.

I am a passionate and adroit Android Programmer. I like to learn new technologies and contribute new ideas and updates to an existing project. I enjoy Blogging too :).
Posts created 14

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top