Unresolved reference: Engine (WallpaperService)

Viewed 275

I'm trying to extend android.service.wallpaper.WallpaperService.Engine class in Kotlin, but I get "Unresolved reference" error:

Unresolved reference: Engine

Even though it is clearly imported above.

Is there any way to fix this?

1 Answers

The issue is that the WallpaperService.Engine is a class enclosed within WallpaperService class (it is obvious once you see it), and is not static, and thus must be tied to a instance of a WallpaperService class, in other words, it must be declared as an inner class of a WallpaperService class:

import android.service.wallpaper.WallpaperService

class MyWallpaperService : WallpaperService() {

    ...

    inner class MyEngine : Engine() {

    }

}
Related