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 isfirstrun
in sharedpreferences.
Comments
Post a Comment