由网友(姐&霸道范儿)分享简介:我试图做一个简单的应用程序安卓。我有两个活动( 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
和 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");
}
}
相关推荐
最新文章