Question

i'm trying to finish my mainactivity after a choosing from the inflated settings menu, but for some reason it does not finish.. any ideas why?

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()){
    case R.id.action_settings:
        Intent i = new Intent (getApplicationContext(), Prefs_Activity.class);
        startActivity(i);
        finish();
        return true;
    default:
    return super.onOptionsItemSelected(item);

    }

}

after finishing the settings activity, with an intent to restart the mainactivity i, end up with a stack of two mainactivities...

my first thought was to move the finish method above the startactivity... but that seems like it would kill the following code...

Was it helpful?

Solution

The activity is in fact closing.. the problem exist in that calling finish in the Prefs_Activity class restarts the activity class from which the startactivity intent was derived, as well as starting the mainactivity with an intent...

as always community, thanks for all your help!

OTHER TIPS

Replace the following code

    Intent i = new Intent (getApplicationContext(), Prefs_Activity.class);
    finishFromChild(CurrentActivity.this);
    startActivity(i);
    return true;

instead of your's

    Intent i = new Intent (getApplicationContext(), Prefs_Activity.class);
    startActivity(i);
    finish();
    return true;

ref:http://developer.android.com/reference/android/app/Activity.html#finishActivityFromChild(android.app.Activity, int)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top