0

I've been developing an application at Android Studio as a college project for a while but I got stuck.

I wanted to know if there is anyway to change activities by not using a button but using a timer. Like: "wait ten seconds then change to that activity".

Thank You.

1 Answers1

1

You can use do it this way

        new Handler().postDelayed(new Runnable() {

         @Override
         public void run() {

         Intent intent = new Intent(this, Another.class);
         startActivity(intent);
            }

         }, 1000);`

or

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
 public void run() {
     // do something
     Intent intent = new Intent(ActivityName.this, Another.class);
     // If you just use this that is not a valid context. Use ActivityName.this
     startActivity(intent);
   }
}, 2000);
Hossam Hassan
  • 795
  • 2
  • 13
  • 39