-1

I have written this code in SplashScreenActivity in onCreate():

Timer t = new Timer();
    boolean checkConnection=new MainActivity().checkConnection(this);
    if (checkConnection) {
      t.schedule(new SplashScreenActivity(), 3000);

    } else {
        Toast.makeText(SplashScreenActivity.this,
                "connection not found...plz check connection", 3000).show();
    }

This is the error I'm getting:

The method schedule(TimerTask, Date) in the type Timer is not applicable for the arguments (SplashScreenActivity, int)

earthw0rmjim
  • 19,027
  • 9
  • 49
  • 63
KiranB
  • 13
  • 6
  • 1
    activities are not meant to be created like that. you should override onCreate. see this: http://stackoverflow.com/a/5486970/26224 – muratgu Aug 08 '16 at 15:28

1 Answers1

0

First of all, you should never instantiate an Activity with the new keyword.

You could for example make checkConnection() a method of SplashScreenActivity.

The cause of the error is the schedule() method expects a TimerTask as its first parameter, but you're passing an Activity to it.

Something like this should work:

if (checkConnection) {
    t.schedule(new TimerTask() {
        @Override
        public void run() {
            Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
            startActivity(intent);
        }
    }, 3000);
} else {
    Toast.makeText(SplashScreenActivity.this,
            "connection not found...plz check connection", Toast.LENGTH_LONG).show();
}
earthw0rmjim
  • 19,027
  • 9
  • 49
  • 63