里面的机器人对话,如何设置onActivityResult的startActivityForResult? [英] inside Android Dialog, how to setup onActivityResult for startActivityForResult?

查看:235
本文介绍了里面的机器人对话,如何设置onActivityResult的startActivityForResult?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个活动,我可以轻松地设置了 onActivityResult()和呼叫 startActivityForResult(),一切工作正常。

现在,我需要调用 startActivityForResult()从对话框。但我不能设置 onActivityResult(),我相信对话框不是活动

我如何得到的结果?

我尝试这样一个对话框内,但失败了。

  //创建新意图
意向意图=新的意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,m_PicUri);
((活动)的getContext())startActivityForResult(意向,Const.TAKE_PIC_ACTIVITY_RET_ code)。
 

解决方案

您可以声明活动有一个对话框主题。看看这个太问题: Android的活动作为一个对话框

您会改变这个在您的的Andr​​oidManifest.xml 文件:

 <活动机器人:主题=@安卓风格/ Theme.Dialog/>
 

您应该可以使用 startActivityForResult()正常人一样。我知道 BluetoothChat 例如Android程序使用类似于返回您从对话框列表中选择蓝牙设备的东西。

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);

解决方案

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.

这篇关于里面的机器人对话,如何设置onActivityResult的startActivityForResult?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆