在onActivityResult数据为空 [英] data in onActivityResult is null
本文介绍了在onActivityResult数据为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一个简单的应用程序安卓
。我有两个活动( A
和 B
)。在 B
我只是想选择一个日期
。
I am trying do a simple application for Android
. I have two Activities (A
and B
). In B
I only want select a date
.
我开始 A
,然后执行:
Intent intent = new Intent();
intent.setClass(this, B.class);
startActivityForResult(intent,1);
然后,在 B
,我做的:
Intent intent = getIntent();
setResult(RESULT_OK);
intent.putExtra("Date",dateSelected);
finish();
和,在 A
,我有一个方法:
And, in A
, i have the next method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK && requestCode==1){
Bundle bundle = getIntent().getExtras();
String aux = bundle.getString("nuevo");
.....
}
但数据
和包
,是空
。当我调试code,我看到,在类 B
,意图
的其他
,但后来,当我打电话完成()
并返回 A级
这个意图
不可访问。
But data
, and bundle
, are null
. When i debug the code, i see that in class B
, intent
has the Extras
, but then, when i call finish()
and return to class A
, this intent
is not reachable.
我该如何解决这个问题呢?
How can i solve this problem?
推荐答案
试试这个:
然后,在B,我做的:
Intent intent = getIntent();
intent.putExtra("Date",dateSelected);
setResult(RESULT_OK, intent);
finish();
和,在答:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(resultCode==RESULT_OK && requestCode==1){
Bundle MBuddle = data.getExtras();
String MMessage = MBuddle .getString("Date");
}
}
这篇关于在onActivityResult数据为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文