image show by timer android studio code example

Example: image show by timer android studio

public class MainActivity extends Activity {

Random random = new Random();
int max = 2;
int min = 0;

ImageView imageView;

Integer[] image = { R.drawable.ic_launcher, R.drawable.tmp,R.drawable.android };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    int randomNumber = random.nextInt(max - min + 1) + min;

    imageView = (ImageView) findViewById(R.id.img);

    imageView.setImageResource(image[randomNumber]);

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            Intent intent = new Intent(MainActivity.this, Act.class);
            startActivity(intent);
        }
    }, 5000);
  }
}

Tags:

Java Example