Possible Duplicate:
Can’t create handler inside thread that has not called Looper.prepare()
I want to call the alertdialogbox in the thread as follows
public class connect implements Runnable
{
public void run() //run method
{
AlertDialog.Builder alert = new AlertDialog.Builder(cordovaExample.activity);
alert.setTitle("Confirm");
alert.setMessage("Are you sure?");
alert.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do nothing but close the dialog
dialog.dismiss();
}
});
alert.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do nothing
dialog.dismiss();
}
});
AlertDialog s = alert.create();
alert.show();
}
}
I am calling this thread from the following activity
public class cordovaExample extends DroidGap
{
Context mcontext;
public static cordovaExample activity;
private static MediaPlayer music=null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
activity=this;
super.init();
new Thread(new connect(this)).start();
}
}
but its giving error Can't create handler inside thread that has not called Looper.prepare()
Any help will be appreciated