Reputation: 176
I have a little problem on my activities... Somehow my onActivityResult method is never called, even though I think I set everything up and don't have "nohistory" or something like this in my manifest.
Activity A:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("ASDSA","ASDSA");
}
Activity B:
Intent intent = new Intent(AddStockActivity.this, MainActivity.class);
intent.putExtra("stock", stock);
setResult(Activity.RESULT_OK, intent);
finish();
The Log never gets executed...Whats wrong with my implementation?
EDIT: Thats how I call the activity:
Intent intent = new Intent(MainActivity.this, AddActivity.class);
startActivityForResult(intent, Activity.RESULT_OK);
Still no action on the logging. I am firing both intents on a button click by the way.
Upvotes: 0
Views: 62
Reputation: 176
Okey guys I figured it out. I needed to change my code into this one:
Intent intent = new Intent(MainActivity.this, AddActivity.class);
startActivityForResult(intent, 1);
Anybody can explain why?
Upvotes: 0
Reputation: 7070
You need to invoke ActivityB
from ActivityA
like this -
Intent intent = new Intent(ActivityA.this, ActivityB.class);
startActivityForResult(intent, <your_request_code_here>);
You don't need to write this in ActivityB
Intent intent = new Intent(AddBienenstockActivity.this, MainActivity.class);
intent.putExtra("stock", stock);
After doing your job just
setResult(Activity.RESULT_OK, intent);
finish();
from ActivityB
Upvotes: 0
Reputation: 2202
Start activity B for result like this
Intent intent = new Intent(ActivityA.this, ActivityB.class);
startActivityForResult(intent, requestCode);
where requestCode
is an integer to distinguish between different requests.
Upvotes: 1
Reputation: 9996
You need to call startActivityForResult
from Activity A instead of startActivity
while firing Intent
Upvotes: 1