Frage

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...

War es hilfreich?

Lösung

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!

Andere Tipps

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)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top