I am trying to display a dialog in a non-Activity class. Basically, I detect an object in my app, I would like to display a dialog and then switch activities. I'm getting a "java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()" in my logcat.
Here is some of my code:
public ImageTargetsRenderer(Context context) {
this.context = context;
mDialog = new ProgressDialog(context);
}
public void onDrawFrame(GL10 gl) {
testFlag = 0;
// DO NOT RENDER IF THERE IS NO TRACKABLE
if (!mIsActive)
return;
// Call our native function to render content
// RENDER IF THERE IS A TRACKABLE
testFlag = renderFrame();
System.err.println("ImageTargetsRenderer reports: " + testFlag);
if(testFlag > 0 && frameCount > 5)
{
frameCount = 0;
System.err.println("Starting to switch activities.");
mDialog.setTitle("Please wait");
mDialog.setMessage("Please wait");
mDialog.show();
new Thread() {
public void run() {
try{
sleep(5000);
} catch (Exception e) { }
// Dismiss the Dialog
mDialog.dismiss();
}
}.start();
Intent myIntent = new Intent(context, FlashActivity.class);
myIntent.putExtra("com.qualcomm.QCARSamples.ImageTargets.flagTest", testFlag);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(myIntent);
testFlag = 0;
return;
}
frameCount++;
}