问题描述
我有一个 DialogActivity
这是从片段
作秀自定义对话称为
有两个图像按钮。
I have a DialogActivity
which is called from a Fragment
for show a custom Dialog
with two image buttons.
在 DialogActivity.onCreate
final Dialog dialog = new Dialog(this, R.style.DialogTheme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_pause);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.show();
在 DialogActivity.onClick
@Override
public void onClick(View v) {
Log.d(LOGTAG, "onClick CONTINUE");
Intent resultData = new Intent();
resultData.putExtra("TEST", "return data");
setResult(666, resultData);
dialog.cancel();
}
在片段调用 startActivityForResult
:
Intent dialogActivityIntent = new Intent(getActivity(), DialogActivity.class);
startActivityForResult(dialogActivityIntent, 999);
在活动
和片段
调用 startActivityForResult
:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
当我按一下按钮我只得到了对话框取消,并显示在后台活动(片段)。
When I click the button I only get the dialog cancel and shows the background activity (fragment).
没有任何调用 onActivityResult
, onResume
,...在片段
或活动
包含片段
。
There isn't any call to onActivityResult
, onResume
, ... in the Fragment
or the Activity
contains the Fragment
.
要落实 onActivityResult
在两个片段
和活动
包含我的片段
。
To implement onActivityResult
in both, Fragment
and Activity
that contains my Fragment
.
我将在每一个的活动属性
我有。 noHistory = TRUE
I set the attribute noHistory=true
in every Activity
I have.
如果我这样做完成()
在的onClick
的活动/片段
调用 DialogActivity
太封闭,并且应用程序返回到活动
。
If I do finish()
in onClick
the Activity/Fragment
that calls DialogActivity
is closed too, and the application return to the before Activity
.
这可能是问题,我不叫完成()
...但如果我叫完成()
,退出到另一个活动
,而不是活动
调用 startActivityForResult
。
This may be the problem, I DON'T call finish()
... but if I call finish()
, it exits to another Activity
, not the Activity
that calls startActivityForResult
.
<一个href="http://stackoverflow.com/questions/10867495/startactivityforresult-dont-call-to-onactivityresultint-request$c$c-int-resu">startActivityForResult()不打电话onActivityResult(INT申请code,INT结果code,意图数据)?
Cannot到达触发onActivityResult()的Android?
startActivityForResult似乎不叫onActivityResult
Android的onActivityResult从来没有所谓的
onActivityResult()在传唤时没有活性的片段
我希望一切都清楚地解释^^。
I hope everything is clearly explained ^^.
在此先感谢。
推荐答案
活动具有属性 noHistory = TRUE
将永远不会有自己的 onActivityResult( )
推出一个新的活动
通过 startActivityForResult时,称为()
。由于documentation提到,当 noHistory
属性设置为真
,然后完成()
是呼吁活动
活动> 。
Activities that have the attribute noHistory=true
will never have their onActivityResult()
called when launching a new Activity
via startActivityForResult()
. As the documentation mentions, when the noHistory
attribute is set to true
, then finish()
is called on the Activity
when the user navigates away from the Activity
.
所以,当 startActivityForResult()
被调用时,活动
是从,导致其<$ C导航离开$ C>完成()来调用,使之永远不会收到呼叫 onActivityResult()
。如果您删除从活动
这是调用 startActivityForResult()的
noHistory = TRUE
属性code>,然后调用完成()
在 DialogActivity
的的onClick( )
,那么你还是应该看到活动
启动它,以及接收呼叫 onActivityResult()
。
So, when startActivityForResult()
is called, the Activity
is navigated away from, causing its finish()
to be called and making it never receive a call to onActivityResult()
. If you remove the noHistory=true
attribute from the Activity
that's calling startActivityForResult()
, then call finish()
in your DialogActivity
's onClick()
, then you should still see the Activity
that launched it, as well as receive a call to onActivityResult()
.
这篇关于从片段通话startActivityForResult不叫onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!