Is it possible to get application's context in an Android Library Project?

后端 未结 5 1436
有刺的猬
有刺的猬 2020-12-04 18:53

I would like to get the context of application which has reference/hosted my library at run-time inside one class of my library project. Is it possible? If yes, how?

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 19:32

    According to this post you can let the library auto-initialize itself with the application context by the aid of a ContentProvider.

    Be careful anyway, as described in the post comments, there may be drawbacks concerning loading time and instant run, as well as crashes on multi-process apps.

    HTH

提交回复
热议问题