I have a splash screen which is being showed only on fresh start of app. If user hit back button and start app again the splash doesn't show. Everything is fine until here, if splash doesn't show, there is a 1-2 second black screen when opening app. Here is my splashactivity java file;
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(!prefs.getBoolean("first_time", false)) // if first time, show splash
{
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("first_time", true);
editor.commit();
setContentView(R.layout.activity_splash);
Thread t = new Thread() {
public void run() {
try {
int time = 0;
while (time < 4000) {
sleep(100);
time += 100;
}
}
catch (InterruptedException e) {
// do nothing
}
finally {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}
};
t.start();
}
else // if not first time, dont show splash
{
setContentView(R.layout.activity_splash);
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
How can I fix this issue ?