Reputation: 1225
I have the Bluetooth
callback that is sometimes triggering twice and makes handling the dialog instance difficult to dismiss()
.
I am declaring the Loader
instance in Global
LoaderProgress mLConnectdialogLoader = new LoaderProgress(InsoleConnection.this);
I trigger the dialog called "Connecting.." for 5 seconds and then dismiss.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mLConnectdialogLoader.dismiss()
}
},5000);
mLConnectdialogLoader.show("Connecting...")
How to prevent the same instance being called twice so that I can avoid having the hard time in dismissing the dialog.
Upvotes: 2
Views: 2177
Reputation: 144
if i got the question ,, you can put the "dialog creation coode" in a synchronized method Learn More About it http://tutorials.jenkov.com/java-concurrency/synchronized.html
Upvotes: 1
Reputation: 503
just create a bool and check its status:
boolean isShown=false;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mLConnectdialogLoader.dismiss();
isShown=false;
}
},5000);
if(!isShown){
mLConnectdialogLoader.show("Connecting...");
isShown= true;
}
Upvotes: 1
Reputation: 4358
if(!mLConnectdialogLoader.isShowing())
mLConnectdialogLoader.show("Connecting...")
In your DialogLoader class:
public boolean isShowing() { return dialog.isShowing(); }
Upvotes: 1