Wednesday, 14 August 2013

Launch an activity only the first time the application starts in android

SharedPreferences prefre=this.getSharedPreferences("firstt", Context.MODE_PRIVATE);
boolean firsttimes=prefre.getBoolean("firstt", true);
if(firsttimes)
{
SharedPreferences.Editor editere=prefre.edit();
editere.putBoolean("firstt", false);
editere.commit();

thread=new Thread()
{
@Override
public void run()
{
super.run();

synchronized (this)
{
try {
wait(3000);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
finish();
Intent intent = new Intent(MainActivity.this,LoginActivity.class);
startActivity(intent);
}
}
}
};
thread.start();
}
else
{
//MainActivity.this.finishActivity(0);
startActivity(new Intent(MainActivity.this, LoginActivity.class));
}

}
You can also see this


http://stackoverflow.com/questions/2960888/launch-an-activity-only-the-first-time-the-application-starts/18231638#18231638