Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show alert dialog in a running thread?

I'm developing an Android Game.In this game, There are tracks on which trains run. This is running thread. I want to show an alert dialog when there is a collision between. when I'm applying alert dialog showing error can't create handler inside thread that has not called looper.prepare().

like image 581
user1602798 Avatar asked Sep 13 '12 06:09

user1602798


People also ask

What is the difference between an alert and an alert dialog?

Dialogs in Android are used to shows alerts for making decisions or to edit a single value. But there are some differences between an AlertDialog and a Dialog. In an AlertDialog you always want to show a message and at least one Button for user interaction.

How do you inflate dialog?

To inflate the layout in your DialogFragment , get a LayoutInflater with getLayoutInflater() and call inflate() , where the first parameter is the layout resource ID and the second parameter is a parent view for the layout. You can then call setView() to place the layout in the dialog.

What is the application of alert () dialog box?

Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.


1 Answers

This will help you:

runOnUiThread(new Runnable() {
    @Override
    public void run() {
        // Your dialog code.
    }
});
like image 80
Ankitkumar Makwana Avatar answered Oct 08 '22 05:10

Ankitkumar Makwana