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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -