Sometimes we want to show some App Introduction and other things as per our requirements so here i am sharing code snippets to determine that the activity open first time using Shared Preference .
So Lets Start :-
for example you want to open App Introduction of your app before going to Main Activity Class so in Main Activity Check that the Activity Opening First time or not Using these lines of Code.
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// Intro App Initialize SharedPreferences
SharedPreferences getSharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
// Create a new boolean and preference and set it to true
Boolean isFirstStart = getSharedPreferences.getBoolean("firstStart", true);
// Check either activity or app is open very first time or not and do action
if (isFirstStart) {
// Launch application introduction screen
// Do whatever you want to do here
SharedPreferences.Editor e = getSharedPreferences.edit();
e.putBoolean("firstStart", false);
e.apply();
}
}
});
t.start();
That's All you need.
Comments
Post a Comment