-1

I am new to android studio and i am doing a splash screen but it won't proceed to the next activity, can anyone help me:

splash.java

`public class splash extends AppCompatActivity{

private TextView tv;
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    tv = (TextView) findViewById(R.id.tv);
    iv = (ImageView) findViewById(R.id.iv);

    Animation myan = AnimationUtils.loadAnimation(this, 
R.anim.mytransition);
    tv.startAnimation(myan);
    iv.startAnimation(myan);

    Thread time = new Thread(){

        public void r () {
            try {
                sleep(5000);
            }catch (InterruptedException e) {
                e.printStackTrace();
            }
            finally {
                startActivity(new Intent(splash.this, MainActivity.class));
                finish();

            }

        }

    };
    time.start();

    }


}`

i can't figure out what's wrong but it just stays at the splash screen.

1 Answers1

2

Your thread creation itself is wrong I believe.Threads can be either created using runnable or by extending thread class

  Thread time = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                sleep(5000);
            }catch (InterruptedException e) {
                e.printStackTrace();
            }
            finally {
                startActivity(new Intent(splash.this, MainActivity.class));
                finish();

            }  
        }
    });
    time.start();

For more info on thread creation

https://www.javatpoint.com/creating-thread
Sharath kumar
  • 4,064
  • 1
  • 14
  • 20