Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

data in onActivityResult is null

Tags:

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?

like image 655
Nobelisco Avatar asked May 10 '12 11:05

Nobelisco


People also ask

What is result code in onActivityResult?

onActivityResult - resultCode is always 0.

What is onActivityResult?

onActivityResult is the callback you have on the first activity to grab the contacts you choose. Follow this answer to receive notifications.

How do I get data from startActivityForResult?

First you use startActivityForResult() with parameters in the first Activity and if you want to send data from the second Activity to first Activity then pass the value using Intent with the setResult() method and get that data inside the onActivityResult() method in the first Activity .


1 Answers

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");     } } 
like image 107
ρяσѕρєя K Avatar answered Sep 23 '22 03:09

ρяσѕρєя K