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

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

    Is it possible?

    Yes.

    If yes, how?

    Pass it in as a parameter.

    I don't want my user to pass context in parameter to my library project because it is possible that my library project will be called through JNI and I have no idea how I can get context in JNI and pass it to Java layer.

    Then figure out "how [you] can get context in JNI and pass it to Java layer". I would imagine that you would pass it like any other object. As @Blundell noted, you do not really have any other option.

提交回复
热议问题