gabrjan gabrjan - 2 months ago 6
Android Question

how to show message for some time and then dismis it in android

So I have main UI thread and there is a function that takes quite some time. So I want to show user something on the screen for that time, but I don't want to mve my function in to the thread because it neads some GUI communication.

so what I need is this

Message msg;
msg.wait("wait dude");
//my code

Any ideas?

I tried putting my code into thread but there is a problem that at the end of code I need to change my view, and I cannot do that from thread.

Answer Source

You can use Toast like the other answers suggested.

You can also use a separate Thread if you have long running code, and use Handler to send message to the main Thread to do changes in the screen.

You can also use, an AsyncTask, this is an Android special Thread that lets you do changes in the view during running, this is done in the doInBackground method.