android - Does opening an activity from a dialog fragment dismisses the dialog fragment? -
i have class inheriting dialogfragment:
import org.xwalk.core.*; // ... public class webviewdialogfragment extends dialogfragment { private xwalkview webview; public static final string log_tag = "webviewdialogfragment"; private string url; private webviewjavascriptinterface javascriptinterface; // constructor use set url. public webviewdialogfragment(string url, webviewjavascriptinterface javascriptinterface) { this.url = url; } public webviewdialogfragment() { log.d(log_tag, "webviewdialogfragment empty constructor called."); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); log.d(log_tag, "setting fullscreen mode"); setstyle(dialogfragment.style_normal, r.style.sagobizwebviewfullscreentheme); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { log.d(log_tag, "setting xwalkview"); webview = new xwalkview(getactivity(), getactivity()); webview.clearcache(true); log.d(log_tag, "loading url: " + url); webview.load(url, null); return webview; } @override public void onstart() { super.onstart(); dialog dialog = getdialog(); if (dialog != null) { int width = viewgroup.layoutparams.match_parent; int height = viewgroup.layoutparams.match_parent; dialog.getwindow().setlayout(width, height); } } @override public void onpause() { super.onpause(); if (webview != null) { webview.pausetimers(); webview.onhide(); } } @override public void onresume() { super.onresume(); if (webview != null) { webview.resumetimers(); webview.onshow(); } } @override public void ondestroy() { super.ondestroy(); if (webview != null) { webview.ondestroy(); } } @override public void onactivityresult(int requestcode, int resultcode, intent data) { if (webview != null) { webview.onactivityresult(requestcode, resultcode, data); } } }
and have class has member of type webviewdialogfragment:
public class webview { protected static final string dialog_fragment_tag = "webviewdialogfragment"; protected activity activity; protected string dialogfragmenttag = dialog_fragment_tag; protected webviewdialogfragment webviewdialogfragment; public webview(activity activity) { this.activity = activity; } public void display(final string url) { log.d("test", "webview display"); activity.runonuithread(new runnable() { @override public void run() { webviewdialogfragment = new webviewdialogfragment(url, getwebviewjavascriptinterface()); if (webviewdialogfragment != null) { fragmentmanager fm; fm = activity.getfragmentmanager(); log.d("test", "showing webview"); webviewdialogfragment.show(fm, webview.this.dialogfragmenttag); } else { log.e("test", "webviewdialogfragment null"); } } }); } }
i call display(string url) method of webview show dialog going show webview.
using @javascriptinterface attribute have created bridge between webview javascript , native java may open external browser (or store) within dialogfragment. javascript interface has method so:
@javascriptinterface public void urlexternalaction(string url) { intent browserintent = new intent(intent.action_view, uri.parse(url)); webview.activity.startactivity(browserintent); }
the problem after opening external activity (from dialog fragment), when come app (either pressing button or task switching) app crashes:
androidruntime java.lang.runtimeexception: unable start activity componentinfo{com.myapp.test/com.myapp.testactivity}:
android.app.fragment$instantiationexception: unable instantiate fragment com.myapp.test.webviewdialogfragment: make sure class name exists, public, , has empty constructor public
i solved crash adding empty constructor webviewdialogfragment, not want. want dialogfragment preserves state.
could me modify code resolve issue?
note parent activity's oncreate not in control , prefer not modify it.
thank , forward input. let me know if part needs better explanation.
fragments , activities need 1 empty contructor, and, if provided, must constructor. if want initialize fragment data, must create fragment , use setarguments method before adding fragment fragment manager. @ question.
Comments
Post a Comment