Android - why Dialog won't be close to dialog.dismiss ()

I have a slightly strange problem. When the action starts, I show a dialog that says that some elements are loaded as follows:

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 a dialog box before declaring the class, and then whenever I try to reject it using dialog.dismiss(); It does not close.

Here you go_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> 

Does anyone know why the dialog doesn't close on dialog.dismiss() ... I'm trying to fire in an asynchronous call after the call. But I checked, and the dialog.dismiss() is executed, for some reason does not close the dialog.

This is how I try to reject the dialog:

 @Override protected void onPostExecute(String result) { dialog.dismiss(); } 
+4
source share
2 answers

Make sure that when you execute dialog.dismiss, it points to the created dialog. You have a dialogue as a class variable, and there is a high probability that at the time of dismissal he was assigned another dialogue. I had this one and it turned out that the dialog box variable during the termination no longer indicates my actual dialog.

Putting a breakpoint and seeing that the dialog variable is the same when creating / executing will probably help

+12
source

Try

 Context mContext = getApplicationContext(); Dialog dialog = new Dialog(mContext); 

according to the documentation, this should be the right way to announce a dialogue.

0
source

Source: https://habr.com/ru/post/1434206/


All Articles