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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -