Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - why would Dialog not close upon dialog.dismiss()

I have a bit of a strange problem. When an activity starts, I show a dialog saying that some items are loading like this:

Dialog dialog;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);        
    setContentView(R.layout.topic_edit);

    dialog = new Dialog (this);

    dialog.setContentView(R.layout.please_wait);
    dialog.setTitle("Loading The Comment.");

    TextView text = (TextView) dialog.findViewById(R.id.please_wait_text);
    text.setText("Please wait while the comment loads...");
    dialog.show();

I declare Dialog dialog right before the class declaration, and then whenever I try to dismiss it with dialog.dismiss(); it doesn't close.

Here is the please_wait.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<TextView
    android:id="@+id/please_wait_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
</RelativeLayout>

Would someone know why the dialog does not close on dialog.dismiss()... I try the dismiss in an async call after the call returns. But I did check, and the line dialog.dismiss() is executed, just for some reason does not close the dialog.

This is how I try to dismiss the dialog:

@Override
protected void onPostExecute(String result) 
{
    dialog.dismiss();
} 
like image 889
Genadinik Avatar asked Dec 09 '22 21:12

Genadinik


1 Answers

Make sure that when you are executing dialog.dismiss that it is pointing to the dialog you created. You have dialog as a class variable and there is a high chance it was assigned another dialog by the time of dismissal come. I had this one and turned out that dialog variable at dismiss time was no longer pointing to my actually dialog.

Putting a break point and seeing if the dialog variable upon creation/execution is still the same will probably help

like image 139
Snake Avatar answered Jan 15 '23 10:01

Snake