I am trying to access SplashScreen activity from an inner class as shown below. But I cant resolve this@SplashScreen
class SplashScreen : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash_screen)
verifyPermissions()
}
private class SplashTimerTask : TimerTask() {
override fun run() {
val mainIntent = Intent(this@SplashScreen, LoginActivity::class.java)
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(mainIntent)
[email protected]()
}
}
}
CodePudding user response:
Try this
private class SplashTimerTask(val splash: SplashScreen) : TimerTask() {
override fun run() {
val mainIntent = Intent(splash, LoginActivity::class.java)
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(mainIntent)
splash.finish()
}
}
or
inner class SplashTimerTask : TimerTask() {
override fun run() {
val mainIntent = Intent(this@SplashScreen, LoginActivity::class.java)
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(mainIntent)
[email protected]()
}
}
CodePudding user response:
this could be resolved by changing the SplashTimerTask like below
private class SplashTimerTask(val splash: SplashScreen) : TimerTask() {
override fun run() {
val mainIntent = Intent(splash, LoginActivity::class.java)
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(splash, mainIntent, null)
splash.finish()
}
}
and calling in SplashScreen like below
_splashTimerTask = SplashTimerTask(this@SplashScreen)