android - Why pressing back button inside of cordova WebView closes app? -
given 2 initialized , added in backstack fragments (one of them see on screen). each fragment has cordovawebview view. in 1 web view have loaded "www.google.com" in "www.bing.com". now, if press button - awaiting, fragment "www.bing.com" poped stack , see google site on device screen. instead of this, app exits (for short time can see google.com, app completly exits)
small part of activity:
cordova.getactivity().getfragmentmanager() .begintransaction() .replace(r.id.fragment_container, webviewfragmentgoogle) .addtobackstack(null) .commit(); cordova.getactivity().getfragmentmanager() .begintransaction() .add(r.id.fragment_container, webviewfragmentbing) .addtobackstack(null) .commit(); fragment:
public class webviewfragment extends fragment { private string murl = "file:///android_asset/www/main.html"; private cordovawebview mwebview; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.webview_fragment,container, false); if (view != null) mwebview = (cordovawebview)view; bundle bundle=getarguments(); string iframeurl = bundle.getstring("iframeurl"); if (!murl.isempty()) { mwebview.loadurl(iframeurl); } return view; } public void gotourl(string url) { mwebview.loadurl(url); } @override public void onresume() { super.onresume(); if (mwebview!= null) { mwebview.handleresume(true, false); } } @override public void onpause() { if (mwebview != null) { mwebview.handlepause(true); } super.onpause(); } @override public void ondestroy() { if (mwebview != null) { mwebview.handlepause(true); mwebview.handledestroy(); } super.ondestroy(); } }
this happens because of cordovawebview.onkeyup() logic - intercepts key strokes , hooks actions on them: in case action is:
this.cordova.getactivity().finish(); personally find killing activity bit intrusive, in case, when cannot configure in way. please check cordovawebview messes onbackpressed method in android details.
Comments
Post a Comment