in my application i am using a canvas and some objects on that.this implementation is done in a separate thread called mythread.in a particular scenario i want to display an alert dialog on my screen.first itried to implement this by using the given below function.
public void StopChecking()
{
if(stopgameflag==true)
{
context=MyActivity.this;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Game Over !!!")
.setCancelable(false)
.setPositiveButton("Play Again",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
setContentView(R.layout.main);
dialog.cancel();
}
})
.setNegativeButton("Exit",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
dialog.cancel();
}
});
Log.d(TAG, "Stopping...oooooooooooooooooooooooooooooo");
}
}
this is a function written in the MyActivity class(main activity).but it is crashing.
somebody said that handlers is the best method to do that.i have searched for the same.but i could not understand anything..
can anyone tell me that how can i implement handlers to display an alert dialog...