0

In a SurfaceView, I'm dispatching new thread that draws on canvas within standard "LockCanvas-Draw-unlockCanvasAndPost" loop. (note that thread doesn't contains message loop).

How to show Android standard Dialog from that thread?

As thread doesn't have msg loop, following code doesn't work:

Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Alert");
builder.setMessage("Stackoverflow!");
builder.setNegativeButton("cancel", null);
builder.show(); 
Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Jox
  • 7,132
  • 14
  • 49
  • 63
  • Can you elaborate on "doesn't work"? `SurfaceView` extends `View`, so can you make reference to its Handler when setting up the thread? – Christopher Orr Jan 11 '10 at 15:06
  • I found interesting info on accesing UI thread from other threads: http://developer.android.com/resources/articles/painless-threading.html – Jox Jan 11 '10 at 17:07

1 Answers1

1

You could pass the second thread a handler that you can send a message on to the first thread that will then show the dialog.

CaseyB
  • 24,780
  • 14
  • 77
  • 112
  • I found (relatively similar) solution to post DialogBuilding code to "Parent" view via ParentView.post(new Runnable() {...}) method. Thanx! – Jox Jan 11 '10 at 17:04