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

后端 未结 5 1439
有刺的猬
有刺的猬 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:19

    I would pass it as a parameter or pass it a singleton in that library.

    Having the main app application extend the library's application class is a bad idea coz in java you can only extend once from a class. If your application requires to pass to another library you will be in trouble.

提交回复
热议问题