Reputation: 479
I have some code here (my activity class and some class, that extends WebViewClient) so, in my activity I do something like this:
protected Dialog onCreateDialog(int id) {
switch(id) {
case 1:
//logging vk dialog
Log.d("OLOLOLO", "webview");
dialog = new Dialog(this);
dialog.setContentView(R.layout.webviewl);
dialog.setTitle("loggin in");
webview = (WebView) dialog.findViewById(R.id.vkWebView);
webview.setWebViewClient(wvClforVK);
webview.loadUrl(url);
// do the work to define the pause Dialog
break;
case 2:
// already logged vk dialog
break;
default:
dialog = null;
}
return dialog;
}
and then call showDialog(1)
on some buttonclick
listener.
In my webview class in onPageFinished()
method I need to dismiss my dialog but I think it will be incorrect to do this:
MyActivity activity = new MyActivity(); //my main activity object
activity.dismissDialog(1);
It doesn't work:
01-03 20:41:10.758: E/AndroidRuntime(1172): java.lang.IllegalArgumentException: no dialog with id 1 was ever shown via Activity#showDialog
How can I get my activity object to correctly dismiss the dialog?
Upvotes: 2
Views: 2757
Reputation: 488
The problem is that you instantiate a new activity which doesn't have any dialog. You have to call the dismissDialog method on the same activity instance in which you created the dialog. If you call it in another class, you have to pass your activity somehow to that class (for example you can pass it as a parameter). Anyway, it is not recommended to instantiate activities in this way, they are instantiated automatically if you defined them in the manifest file of your project.
Upvotes: 3
Reputation: 5322
As the exception says, you are trying to dismiss a dialog that was not shown before using showDialog. You need to check the life cycle of the dialog. You can use Dialog.isShowing()
method to confirm the dialog is shown before dismissing it.
Upvotes: 1