Khaled Shoushara
Khaled Shoushara

Reputation: 69

Apply SplashScreen without making Thread and run()

there is my code .. I wanna make splash screen without Thread timer .. How can I do that ?

public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Thread timer = new Thread() {
        public void run() {
            try {
                sleep(2000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                // myCode();

                }
            }
        }
    };
    timer.start();
} }

Upvotes: 0

Views: 43

Answers (1)

Amin Rahkan
Amin Rahkan

Reputation: 119

you can use following code , i think is good for you.

   public class SplashActivity extends AppCompatActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
     new Handler().postDelayed(new Runnable(){
        @Override
        public void run() {
            Intent mainIntent = new 
            Intent(SplashActivity.this,AnotherActivity.class);
            startActivity(mainIntent);
            finish();
        }
    },3000);
   }
 }

Upvotes: 1

Related Questions