简体   繁体   中英

How to Send Message From AlertDialog to Activity

I'm trying to ask the user if he wants to retry a login process if the initial one has failed. I do this using an AlertDialog. The problem is i'm going around in a circle. Let me explain: I have the login method named Login which I call from the main activity. If this fails, I open an AlertDialog. The response from AlertDialog comes on the main thread. How do I make the AlertDialog dissapear before I call Login again?

Now I have something like this onCreate->Login->AlertDialog->ResponseHandler->Login. If I do this, the AlertDialog will never close because everything happens on the same thread.

Is there a way to send the response from the AlertDialog to the activity in a asynchronous way?

You can declare a Handler object as an anonymous inner class in your activity and on its reference call the sendEmptyMessage(0) . in the handlerMessage() of the handler instance just dismiss the AlertDialog .

Here is a tutorial link which will help you more http://www.tutorialforandroid.com/2009/01/using-handler-in-android.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM