inside Android Dialog, how to setup onActivityResult for startActivityForResult?

tony-p-lee  picture tony-p-lee · Aug 27, 2011 · Viewed 13.9k times · Source

From an activity, I can easily setup the onActivityResult() and call startActivityForResult() and everything works fine.

Now, I need to call startActivityForResult() from the Dialog. But I can't setup the onActivityResult(), I believe Dialog is not an Activity.

How do I get the result?

I try something like this inside a dialog but it failed.

//create new Intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, m_PicUri);
((Activity) getContext()).startActivityForResult(intent, Const.TAKE_PIC_ACTIVITY_RET_CODE);

Answer

trevor-e picture trevor-e · Jul 23, 2012

You can declare your Activity to have a Dialog theme. Look into this SO question: Android Activity as a dialog

You would change this in your AndroidManifest.xml file:

<activity android:theme="@android:style/Theme.Dialog" />

You should be able to use startActivityForResult() like normal. I know the BluetoothChat example Android program uses something similar to return the Bluetooth device that you choose from a Dialog list.