android - Restart app properly -



android - Restart app properly -

i utilize code restart app.

intent i=getbasecontext().getpackagemanager().getlaunchintentforpackage(getbasecontext().getpackagename()); i.addflags(intent.flag_activity_clear_top | intent.flag_activity_new_task); startactivity(i);

it restart app, jumps first launch activity. goes fragment intent executed when press back.

then added nullify backstack:

fm.popbackstack(null, fragmentmanager.pop_back_stack_inclusive);

then when press button goes activity holding fragment earlier.

question:

should override onbackpressed on first launch activity or there improve way?

screen - splash

screen b - first launched screen

screen c - main

here happens when restart (from main) without finish: c -> b -> -> *back pressed -> c

so added finish, here happens: c -> b -> *closes, not crash

but found answer.

if want activity stack home screen, if user presses back button exit application add together these 2 flags

flag_activity_clear_top , flag_activity_single_top

intent = new intent (this, home.class); i.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top); startactivity(i);

this finish activities in stack between current activity , 1 starting.

hope give idea. happy coding.

i'm assuming want exit application after restart

android android-intent android-fragments

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -