I call an activity for result:
private static final int CODE_LOGIN = 0;
private static final int CODE_DETAILS = 1;
private void callDetailsActivity() {
Intent switchToDetailsActivity = new Intent(getApplicationContext(), Details.class);
switchToDetailsActivity.putExtra(TAG_ID, details.get(TAG_ID));
startActivityForResult(switchToDetailsActivity, CODE_DETAILS);
}
Now in my Details.class i call to get back to the previous activity:
@Override
public void onBackPressed() {
setResult(RESULT_OK);
super.onBackPressed();
}
And then my onActivityResult()
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == CODE_LOGIN) {
// This is for my other Activity, where the "return" works
}
}
updateOffers();
}
But insead of going back to my previous class the application is closed without any error logs. When I press the home button to go to my previous application, I can go to my application and then I am in my previous activity, but thats definately not the way it is supposed to work.
I also tried not to change onBackPressed()
, or simply write finish()
into onBackPressed()
, but nothing worked.
I haven't set android:noHistory="true"
With my other Activity (which uses excatly the same code), it works perfectly (CODE_LOGIN).
Can somebody help me?
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
exit(); or finish(); it exit full application or all activity.
If you want to exit an activity you should just call finish() .
A Service method onTaskRemoved will be called when we remove app from recent items.
Maybe you have declared the first activity as android:noHistory="true" in AndroidManifest?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With