I'm a Android beginer. I have made a SplashScreen changing img picture inside ImageView evry 2 seconds. Last image is shown two times in row to avoid dissaper it immediately before move to MainActivity. So It works somehow - pictures are changing and finally it takes user to MainActivity where I have just one button which does nothing(just to have enything visible there for test). Theoretically everything is fine but each 8 seconds MainActivity is probably reload again. I can see that becouse Button is jumping 1px down and up.
Could you please take a look on my code and answer the question Why? Thank You!
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash_screen);
handler.postDelayed(runnable, 0);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
int[] imageArraySplashScreen = { R.drawable.pierwszy, R.drawable.drugi, R.drawable.trzeci, R.drawable.trzeci};
Handler handler = new Handler();
Runnable runnable = new Runnable(){
int i = 0;
ImageView splashImageView;
public void run() {
splashImageView = findViewById(R.id.idSplashScreenImageView);
splashImageView.setImageResource(imageArraySplashScreen[i]);
i++;
if (i>imageArraySplashScreen.length-1){
i=0;
Intent splashScreenIntent = new Intent(SplashScreen.this, MainActivity.class );
startActivity(splashScreenIntent);
finish();
}
handler.postDelayed(this, 2000);
}
};
}