0

I want to execute a piece of code So that users can pay attention to my LOGO Like other APP

I want to use timer Execution setContentView. Compiler is not wrong. But execution error. unfortunately has stopped.

Timer timer;

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

        public void abc() {

             timer = new Timer();

            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                      goToLayout1();    
                }

                private void goToLayout1() {
                    setContentView(R.layout.activity_main2);
                            timer.cancel();
                }
            }, 1000, 2000);
        }


}
Walid Hossain
  • 2,724
  • 2
  • 28
  • 39

2 Answers2

2

I suggest you should have two activity.First activity is for showing splash screen.You can finish this after 3 seconds and start another activity that is activity with the layout actitiy_main2.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Runnable runnable=new Runnable(){
    public void run(){
    finish();
    //start main activity
      }
    };
  Handler handler=new Handler();
  handler.postDelayed(runnable,3000);
}
Rasel
  • 15,499
  • 6
  • 40
  • 50
1

you are attempting to modify the UI thread from a non-UI thread (a simple java timer) so please, take care of it and read this Update UI from Thread. Then please, post the exception!

Community
  • 1
  • 1
Yngwie89
  • 1,217
  • 9
  • 17