android - Ignore a certain webpage when pressing back button -
recently added local error page android webview app. when webpage fails load properly, shows local html file.
webview.setwebviewclient(new webviewclient() { //on error, open local file public void onreceivederror(webview view, int errorcode, string description, string failingurl) { webview.loadurl("file:///android_asset/www/myerrorpage.html"); } });
my code when button pressed:
private boolean exit = false; private long timestamp = 0; private handler handler = new handler(); @override // detect when button pressed public void onbackpressed() { if(webview.cangoback()) { webview.goback(); } else { if (exit) { exit = false; //added this.finish(); } else { //added: if (timestamp == 0 || (system.currenttimemillis() - timestamp) > 3000) { toast.maketext(this, "press again close.", toast.length_short).show(); exit = true; timestamp = system.currenttimemillis(); //added handler.postdelayed(new runnable() { @override public void run() { exit = false; } }, 3 * 1000); } } } }
specific problem:
when press button previous page "file:///android_asset/www/myerrorpage.html", should ignore errorpage , go go last webpage loaded correctly. how can this?
@override public void onbackpressed() { if (wvcontactus.cangoback()) { wvcontactus.goback(); } else { super.onbackpressed(); } } webview.setwebviewclient(new webviewclient() { //on error, open local file public void onreceivederror(webview view, int errorcode, string description, string failingurl) { webview.loadurl("file:///android_asset/www/myerrorpage.html"); onbackpressed(); } });
Comments
Post a Comment