In my case I didn't want to create a new Activity only to show a image for 2 seconds. When starting my MainAvtivity
, images gets loaded into holders using picasso, I know that this takes about 1 second to load so I decided to do the following inside my MainActivity OnCreate
:
splashImage = (ImageView) findViewById(R.id.spllll);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
int secondsDelayed = 1;
new Handler().postDelayed(new Runnable() {
public void run() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
splashImage.setVisibility(View.GONE);
}
}, secondsDelayed * 2000);
When starting the application the first thing that happens is the ImageView
gets displayed and the statusBar is removed by setting the window flags to full screen. Then I used a Handler
to run for 2 seconds, after the 2 seconds I clear the full screen flags and set the visibility of the ImageView
to GONE
. Easy, simple, effective.