android 未解析的引用:从内部类别存取SplashScreen时,这个@SplashScreen

pftdvrlh  于 2022-12-09  发布在  Android
关注(0)|答案(2)|浏览(161)

我正在尝试从内部类访问SplashScreen活动,如下所示。但无法解析此@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)
            this@SplashScreen.finish()
        }
    }
}
xdyibdwo

xdyibdwo1#

试试这个

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()
    }
}

inner class SplashTimerTask : TimerTask() {

        override fun run() {
            val mainIntent = Intent(this@SplashScreen, LoginActivity::class.java)
            mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            startActivity(mainIntent)
            this@SplashScreen.finish()
        }
    }
w8rqjzmb

w8rqjzmb2#

这可以通过如下更改SplashTimerTask来解决

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()
    }
}

并在SplashScreen中调用,如下所示

_splashTimerTask = SplashTimerTask(this@SplashScreen)

相关问题