【发布时间】:2019-09-03 18:03:30
【问题描述】:
我正在使用Youtube Extractor library
implementation 'com.github.HaarigerHarald:android-youtubeExtractor:master-SNAPSHOT'
我正在使用它在我的片段中获取 YouTube 下载 URL,一旦它完成提取就会上传到我的 firebase 数据库
if (requestCode==0000 && resultCode==getActivity().RESULT_OK){
if (videoPath != null ) {
for (String s : videoPath) {
new YouTubeExtractor(context) { // THIS LIBRARY SHOWING WARNING
@Override
protected void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta videoMeta) {
if (ytFiles !=null){
int itag = 18;
String link = ytFiles.get(18).getUrl();
Map<String, Object> map = new HashMap<>();
map.put("Message", link);
String Temp_Key = databaseReference.push().getKey();
Map<String, Object> RoomKey = new HashMap<>();
databaseReference.updateChildren(RoomKey);
DatabaseReference message_Root = databaseReference.child(Temp_Key);
message_Root.updateChildren(map);
}
}
}.extract(s, true, true);
}
}
我的问题是如何用这个库解决这个警告。我不想使用@SuppressLint("StaticFieldLeak"),它只会抑制警告而不是解决它。
【问题讨论】:
-
好吧,如果 AsyncTask 没有声明为静态的,它可能会导致泄漏,因为它不支持生命周期。因此,例如,当您旋转设备时,如果您不手动销毁任务,它可能会保留对已销毁对象的引用,从而导致泄漏。如果你想解决这个问题,你需要将 AsyncTask 设为静态。
-
@T.Mas 因为我正在使用这个库,所以我无法提供它
WeakReference。也不能修改库方法。任何解决方案
标签: java android android-asynctask static