android - Open activity only for the first run -


i have button in first layout , want when user clicks on it, shows activity , never shows first activity.

i tried :

boolean isfirstrun = getsharedpreferences("preference", mode_private)         .getboolean("isfirstrun", true);  if (isfirstrun) {     //show start activity     startactivity(new intent(mainactivity.this, firstlaunch.class));     toast.maketext(mainactivity.this, "first run", toast.length_long)             .show(); }  getsharedpreferences("preference", mode_private).edit()             .putboolean("isfirstrun", false).commit(); 

i doubt, because may won't hit getsharedpreferences() line, , navigated new activity firstlaunch.

so think should like,

if (isfirstrun) {     //show start activity     getsharedpreferences("preference", mode_private).edit()             .putboolean("isfirstrun", false).commit();     startactivity(new intent(mainactivity.this, firstlaunch.class));     toast.maketext(mainactivity.this, "first run", toast.length_long)             .show(); } 

so basically, before navigate firstlaunch activity have save state of isfirstrunin sharedpreferences.


Comments

Popular posts from this blog

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -