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
before invoke wait need get the object lock like this:
synchronized(Thread.currentThread()) { //added
try {
Thread.currentThread().wait();
} catch (InterruptedException e) {
Log.e("Attractivometer","Main Thread interrupted while waiting");
e.printStackTrace();
}
}
but why you want to make main thread wait?
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.
No, no, no! Do not block the UI thread. The system will raise an "Application Not Responding" error. Also, do not try to interact with the user from a non-UI thread.
When the user clicks "edit", don't start the edit method. Just pop up a dialog to collect the required information. Add a DialogInterface.OnClickListener
to the positive button and (with the required information now in hand) start the edit method from there.
See the guide topic Dialogs for more information.