【发布时间】:2015-06-24 18:26:46
【问题描述】:
我已经开发了几个星期的安卓应用程序,并且时不时地看到这个问题:
06-24 14:04:48.915 1530-1539/android.process.acore E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:180)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:916)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:906)
at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:57)
at android.os.Binder.execTransact(Binder.java:446)
我能想到的唯一原因是我使用以下代码在浏览器中打开了一个 url:
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.practiceadmin.com/legal/"));
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(browserIntent);
}
};
奇怪的是,当我打开我的 android.os.ParcelFileDescriptor.java 文件时,它对导入语句说:
import dalvik.system.CloseGuard;
import libcore.io.IoUtils;
import libcore.io.Memory;
它无法解析符号“CloseGaurd”/“libcore”。 任何解决此问题的方向将不胜感激。
【问题讨论】:
-
好的,我将尝试使用 MAT 和 DDMS 来解决这个问题。如果我不能解决它,我会回来。
-
与BackupAgent 相关的类显示在堆栈跟踪中。您是否在应用程序中对 BackupAgent 进行了子类化并在清单中声明了它?如果是这样,您可能希望开始在该代码中查找未释放的资源。
标签: java android file-descriptor parcel