Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, finish() closes application insead of activity

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?

like image 360
degude Avatar asked Oct 18 '13 12:10

degude


People also ask

What does finish () do in Android?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.

How do I close all activities on Android?

exit(); or finish(); it exit full application or all activity.

How do you exit an activity?

If you want to exit an activity you should just call finish() .

Which method is called when app is closed?

A Service method onTaskRemoved will be called when we remove app from recent items.


1 Answers

Maybe you have declared the first activity as android:noHistory="true" in AndroidManifest?

like image 122
magda Avatar answered Sep 19 '22 17:09

magda