How to config SharedPreferences for the first run activity in the Android? -


i have 3 activity:

1- splashscreensactivity

2- introactivity

3- mainactivity

i need do, @ first launch appliation start introactivity else mainactivity after splashscreenactivity .

edited:
i wrote code did not work , after showing splash screen, mainactivity started , introactivity never start.

plese let me know problem.

intro.java:

    sharedpreferences settings=getsharedpreferences("prefs", 0);     final boolean firstrun=settings.getboolean("firstrun",false);     if(firstrun==false)     {         sharedpreferences.editor editor=settings.edit();         editor.putboolean("firstrun",true);         editor.commit();         intent i=new intent(intro.this,intro.class);         startactivity(i);         finish();     }     else     {         intent a=new intent(intro.this,mainactivity.class);         startactivity(a);         finish();     } 


splashscreeactivity.java:

public class splashscreensactivity extends activity {  private imageview mlogo; private textview welcometext;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     getwindow().requestfeature(window.feature_no_title);      setcontentview(r.layout.activity_splash_screen);      typeface roboto_s = typeface.createfromasset(getassets(), "roboto-thin.ttf");     mlogo = (imageview) findviewbyid(r.id.logo_sp);     welcometext = (textview) findviewbyid(r.id.welcome_text);     welcometext.settypeface(roboto_s);      animation animation2;{         mlogo.setalpha(1.0f);         animation anim = animationutils.loadanimation(this, r.anim.translate_top_to_center);         mlogo.startanimation(anim);     }     animation animation3; {         objectanimator alphaanimation = objectanimator.offloat(welcometext, "alpha", 0.0f, 1.0f);         alphaanimation.setstartdelay(700);         alphaanimation.setduration(1200);         alphaanimation.start();     }       handler handler = new handler();     handler.postdelayed(new runnable() {     @override     public void run() {         // todo auto-generated method stub         finish();         intent next = new intent(getbasecontext(), intro.class);//         startactivity(next);         }     }, 2000); } 

}

the problem solved change in splashscreenactivity.
so 've edited handler codes in splashscreenactivity:

        handler handler = new handler();         handler.postdelayed(new runnable() {         public void run() {             if (settings.getboolean("isfirstrun", true)) {                 sharedpreferences.editor editor = settings.edit();                 editor.putboolean("isfirstrun", false);                 editor.commit();                 intent next = new intent(splashscreensactivity.this, intro.class);                 startactivity(next);             } else {                 intent next2 = new intent(splashscreensactivity.this, mainactivity.class);                 startactivity(next2);                 finish();             }         }     }, 2000); } 

and remove firstrun method intro.java
i hope useful


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -