Can't create handler inside thread that has not called Looper.prepare()

Error message: In Android development, if a ProgressDialog is started in a Thread to prompt the connection (that is, to prevent suspended animation), and then dismiss() the ProgressDialog in the Handler, the program will hang directly, and the exception information is: Can 't create handler inside thread that has not called Looper.prepare()

Reason analysis: The situation I encountered is that at the beginning of the program, the ProgressDialog is called to prompt the connection (anti-feign death call), and later after the connection is successful, the ProgressDialog is dismissed (), if there is an error message (such as connection failure or something), it is in The Toast prompt is called in the thread, and then when the program runs to the Toast place, the program hangs directly

Solution: Add Looper.prepare() in front of the place where Toast (or AlertDialog) is called, and then add Looper.loop() to solve the problem; that is to say, use Looper.prepare() and Looper.loop() Wrap the toast front and back.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326630905&siteId=291194637