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
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
nice tutorial . keep it up
ReplyDeleteShould we do this inside onCreate() of the main activity?
ReplyDeleteAaditya we can do.
ReplyDeleteBut if you can do in onresume. It will more effective
Not Working , the app crashes on exiting
ReplyDeletehandler = new Handler();
Deletefinal Runnable r = new Runnable() {
public void run() {
tv.append("Hello World");
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);
in destroy method please remove callback from handler
Please i want to show this activity only 3 times not once, How to do it ?
ReplyDelete