Android: Wait() the main thread while a dialog gets input in a separate Thread

后端 未结 3 1789
一整个雨季
一整个雨季 2020-12-21 04:37

I\'m writing an activity in Android where the user modifies an SQL Database. The UI consists of an EditText where the user enters the name, and a Seekbar where the user ente

3条回答
  •  礼貌的吻别
    2020-12-21 05:25

    First of all, you should not pause the main Thread, because everything will be frozen if you do that, and from an user perspective, that is not good at all.

    And second, you should pop up a dialog with 2 buttons, (Done, Cancel) and allow user to go further by pressing one of those buttons. Here you can find out how to display a custom dialog: http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application

    First rule of multi-thread programming in Android is that, You should never stop UI thread, and all the long running operations should be made in separate thread. And by long running operations I mean, SQLite database writing/ reading etc.

提交回复
热议问题