How to obtain AssetManager without reference to Context?

后端 未结 2 496
不思量自难忘°
不思量自难忘° 2020-12-13 20:31

I have a class that needs to obtain a reference to it\'s application\'s AssetManager. This class does not extend any sort of android UI class, so it doesn\'t h

2条回答
  •  暖寄归人
    2020-12-13 20:42

    I am not sure of the best answer to the OP question. However, I do know that you have to be very careful when using a static context as suggested in Android developer resources:

    In the onCreate() method of your app instance, save your context (e.g. this) to a static field named app and create a static method that returns this field, e.g. getApp():

    Using static contexts can leak to leaked memory issues, especially if the static context is used for references to views.

提交回复
热议问题