Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

android - data in onActivityResult is null

I am trying do a simple application for Android. I have two Activities (A and B). In B I only want select a date.

I start A, and do:

 Intent intent = new Intent();
 intent.setClass(this, B.class);
 startActivityForResult(intent,1);

Then, in B, I do:

 Intent intent = getIntent();
 setResult(RESULT_OK);
 intent.putExtra("Date",dateSelected);
 finish();

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");
        .....
    }

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this:

Then, in B, I do:

Intent intent = getIntent();
intent.putExtra("Date",dateSelected);
setResult(RESULT_OK, intent);
finish();

And, in A:

@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");
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...