Saturday, 10 September 2016

How to activity execute once when install app

I share code that is use to execute actvity once

SharedPreferences settings=getSharedPreferences("prefs",0);
boolean firstRun=settings.getBoolean("firstRun",false);
if(firstRun==false)//if running for first time//Splash will load for first time{
   
   SharedPreferences.Editor editor=settings.edit();
    editor.putBoolean("registration",true);
    editor.commit();
   Intent a=new Intent(Splash_Activity.this,MainActivity.class);
        a. addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK| Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(a)
} else{ Intent a=new Intent(getApplicationContext(),TweenMation_Activity.class); startActivity(a); finish(); }

No comments:

Post a Comment