-2

This is my code. The main activity won't run after the splash screen and no errors appeared. The app is getting crashed after the splash screen.

Splash Activity

package com.example.collegematch;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        getSupportActionBar().hide();   


        Thread thread = new Thread(){

            public void run(){
                try {
                    sleep(2000);
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
                finally {
                    Intent intent = new Intent(SplashActivity.this , MainActivity.class);
                    startActivity(intent);
                    finish();

                }
            }
        };
        thread.start();
    }
}
Ryan M
  • 18,333
  • 31
  • 67
  • 74
Grv
  • 1
  • 2
    1. It is considered bad practice by Google to have a fake loading on Splash screens. 2. Can you share the exception log (from logcat)? – gioravered Sep 05 '21 at 08:22
  • It's very difficult to debug a crash without a stack trace. See [Unfortunately MyApp has stopped. How can I solve this?](/q/23353173) for Android-specific advice, and [What is a stack trace, and how can I use it to debug my application errors?](/q/3988788) for advice on what to do once you have the stack trace. If you still need help, edit your question to include the **complete stack trace**, as well as **which line of your code** the stack trace points to. – Ryan M Sep 09 '21 at 15:55

1 Answers1

0

Change the code to:

val handler = Handler(mainLooper)
        handler.postDelayed(
            {
                startActivity(
                    new Intent(SplashActivity.this , MainActivity.class)
                );
                finish();
            }, 1000
        )

It is not recommended to make splash screen like this. Please read this.

Ashique Bava
  • 2,486
  • 2
  • 9
  • 21