我在onCreate()
中创建了这样的变量:
DataClient dataClient = Wearable.getDataClient(this)
然后我将此变量传递给构造函数中的静态AsyncTask 。我在doInBackground()
中使用它。据我了解-那是一个漏洞(在异步任务中使用上下文相关的变量会阻止GC清除活动直到任务完成)。
可能的解决方案是使用对dataClient
的弱引用。
参考力弱的问题是,我听说您不能在doInBackground()
中仅在onPostExecute()
中取消引用,而在doInBackground()
中则需要取消引用。
我该怎么办?