Reputation: 65
I want to make splash screen appear when user launch my app (as usual), but because i will be using animated splash screen i dont want to bother user with same animation every time he opens app, so he need to wait 3 seconds for animation to finish.
So..
How can i make app not to display splash screen if user already opened app, and app should check when opening was he been in cached state, and then called again, so it shouldn't display splash screen when he is called from cached memory.
Because in that way, it means he is not being destroyed from user, so user can fast go from one app to another.
It's like in google calendar, it bothers me to see splash screen every time i open it, but everything i want to do i check some notes and go back in calendar to make some events from notes. Calendar take me time with his splash screen every time. But it is still good splashscreen when i start it when i didntused it in a while.
Or i should use onPause() in MainActivity, and onDestroy() methods to achieve that. And if so, how i can do that, how NOT to display splash screen when i have one instantiated?
Upvotes: 0
Views: 332
Reputation: 735
Create one Preference Manager class to store a boolean value to store a splash screen check if launch or not.
public class PrefManager {
private static final String KEY_IS_SPLASH_IN = "isSplashScreenIn";
SharedPreferences pref;
// Editor for Shared preferences
Editor editor;
// Context
Context _context;
// Shared pref mode
int PRIVATE_MODE = 0;
public PrefManager(Context context) {
this._context = context;
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
}
public boolean isSplashIn() {
return pref.getBoolean(KEY_IS_SPLASH_IN, false);
}
public void setSplashIn(boolean setLogin) {
editor.putBoolean(KEY_IS_SPLASH_IN, setLogin);
editor.commit();
}
}
Using a preference manager class in splash screen
public class SplashActivity extends Activity{
PrefManager pref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
pref = new PrefManager(this);
if (pref.isSplashIn == false) {
//Splash Screen Load
pref.setSplashIn(true);
} else {
Intent registration = new Intent(ctx, Login.class);
startActivity(registration);
}
}
}
Thanks, Happy Coding.....
Upvotes: 1