Question

currently I'm programming an Android application and I'm using timer for my splash. instead of using timer I want to use handle but I can't integrate that to my code:

package com.tesbih;

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

public class Splash extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
     // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.splash);
    Thread timer = new Thread(){

         public void run(){
             try{
                sleep(5000);
            }catch(InterruptedException e){

                e .printStackTrace();

            }finally{

            Intent openStartingPoint = new Intent ("com.tesbih.TESBIHMAINACTIVITY");
            startActivity(openStartingPoint);

            }
        }   
      };

      timer.start();
    }
  }
Was it helpful?

Solution

public class Splash extends Activity {    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.splash);

        final Intent openStartingPoint = new Intent(this, TESBIHMAINACTIVITY);
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                startActivity(openStartingPoint);
                finish();
            }
        }, 5000);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top