BestPractice2Go
BestPractice2Go

Reputation: 305

Can't inject Application context in abstract class

I have in my AppModule following notation:

@Provides
@ApplicationContext
fun provideAppContext(app: Application): Context = app

and I want to use it in abstract class

@Inject
@ApplicationContext
lateinit var mContext: Context

But when I try to use the context (for call ressources.getString(..)), I get following error:

lateinit property mContext has not been initialized

Upvotes: 0

Views: 258

Answers (1)

SIVAKUMAR.J
SIVAKUMAR.J

Reputation: 4354

for abstract class u cannot able to call the constructor.So better to use child class.

Upvotes: 1

Related Questions