我的片段正在生成大量磁盘读取严格模式违规并在我执行小型投掷或滚动时闪烁屏幕。我正在使用Android 4.4.2在Samsung上运行该应用程序。
使用自定义游标适配器从自定义内容提供程序填充片段中的列表视图。我没有处理任何可能触发磁盘读取的fling或scroll事件。在片段启动时获取这些违规是合理的,因为我在getLoaderManager().initLoader()
中onResume()
。但是我不明白为什么这个片段会在fling上尝试读取磁盘。
在生成标记StrictMode
的大约500条logcat行中,我在这里粘贴了一些。知道是什么导致了这个吗?
@TargetApi(11)
public static void enableStrictMode() {
// Strict mode is only available on gingerbread or later
if (Utils.hasGingerbread()) {
// Enable all thread strict mode policies
StrictMode.ThreadPolicy.Builder threadPolicyBuilder =
new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog();
// Enable all VM strict mode policies
StrictMode.VmPolicy.Builder vmPolicyBuilder =
new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog();
// Honeycomb introduced some additional strict mode features
if (Utils.hasHoneycomb()) {
// Flash screen when thread policy is violated
threadPolicyBuilder.penaltyFlashScreen();
// For each activity class, set an instance limit of 1. Any more instances and
// there could be a memory leak.
vmPolicyBuilder
.setClassInstanceLimit(ContactsListActivity.class, 1)
.setClassInstanceLimit(ContactDetailActivity.class, 1);
}
// Use builders to enable strict mode policies
StrictMode.setThreadPolicy(threadPolicyBuilder.build());
StrictMode.setVmPolicy(vmPolicyBuilder.build());
}
}
Logcat:
StrictMode policy violation; ~duration=15 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=2335 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1156)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:106)
at libcore.io.IoBridge.open(IoBridge.java:393)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
at com.android.server.ssrm.SSRMUtil.writeSysfs(SSRMUtil.java:134)
at com.android.server.ssrm.CustomFrequencyManagerService.acquireCpuDvfsLock(CustomFrequencyManagerService.java:2321)
at com.android.server.ssrm.CustomFrequencyManagerService.acquireDVFSLockLocked(CustomFrequencyManagerService.java:1929)
at com.android.server.ssrm.CustomFrequencyManagerService.acquireDVFSLock(CustomFrequencyManagerService.java:1880)
at android.os.ICustomFrequencyManager$Stub.onTransact(ICustomFrequencyManager.java:274)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
# via Binder call with stack:
android.os.StrictMode$LogStackTrace
at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1726)
at android.os.Parcel.readExceptionCode(Parcel.java:1447)
at android.os.Parcel.readException(Parcel.java:1416)
at android.os.ICustomFrequencyManager$Stub$Proxy.acquireDVFSLock(ICustomFrequencyManager.java:766)
at android.os.CustomFrequencyManager$CPUDVFSControlRequest.doFrequencyRequestImpl(CustomFrequencyManager.java:458)
at android.os.CustomFrequencyManager$FrequencyRequest.doFrequencyRequest(CustomFrequencyManager.java:218)
at android.os.DVFSHelper.acquire(DVFSHelper.java:495)
at android.os.DVFSHelper.acquire(DVFSHelper.java:288)
at android.widget.AbsListView.reportScrollStateChange(AbsListView.java:5433)
at android.widget.AbsListView.startScrollIfNeeded(AbsListView.java:3858)
at android.widget.AbsListView.onTouchMove(AbsListView.java:4745)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:4600)
at android.view.View.dispatchTouchEvent(View.java:8149)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2140)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2295)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1622)
at android.app.Activity.dispatchTouchEvent(Activity.java:2565)
at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2243)
at android.view.View.dispatchPointerEvent(View.java:8357)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4778)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4644)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
at
StrictMode policy violation; ~duration=14 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=2335 violation=1
at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1130)
at libcore.io.BlockGuardOs.write(BlockGuardOs.java:196)
at libcore.io.IoBridge.write(IoBridge.java:450)
at java.io.FileOutputStream.write(FileOutputStream.java:187)
at java.io.OutputStream.write(OutputStream.java:82)
at com.android.server.ssrm.SSRMUtil.writeSysfs(SSRMUtil.java:135)
at com.android.server.ssrm.CustomFrequencyManagerService.acquireCpuDvfsLock(CustomFrequencyManagerService.java:2321)
at com.android.server.ssrm.CustomFrequencyManagerService.acquireDVFSLockLocked(CustomFrequencyManagerService.java:1929)
at com.android.server.ssrm.CustomFrequencyManagerService.acquireDVFSLock(CustomFrequencyManagerService.java:1880)
at android.os.ICustomFrequencyManager$Stub.onTransact(ICustomFrequencyManager.java:274)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
# via Binder call with stack:
android.os.StrictMode$LogStackTrace
at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1726)
at android.os.Parcel.readExceptionCode(Parcel.java:1447)
at android.os.Parcel.readException(Parcel.java:1416)
at android.os.ICustomFrequencyManager$Stub$Proxy.acquireDVFSLock(ICustomFrequencyManager.java:766)
at android.os.CustomFrequencyManager$CPUDVFSControlRequest.doFrequencyRequestImpl(CustomFrequencyManager.java:458)
at android.os.CustomFrequencyManager$FrequencyRequest.doFrequencyRequest(CustomFrequencyManager.java:218)
at android.os.DVFSHelper.acquire(DVFSHelper.java:495)
at android.os.DVFSHelper.acquire(DVFSHelper.java:288)
at android.widget.AbsListView.reportScrollStateChange(AbsListView.java:5433)
at android.widget.AbsListView.startScrollIfNeeded(AbsListView.java:3858)
at android.widget.AbsListView.onTouchMove(AbsListView.java:4745)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:4600)
at android.view.View.dispatchTouchEvent(View.java:8149)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2140)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2295)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1622)
at android.app.Activity.dispatchTouchEvent(Activity.java:2565)
at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2243)
at android.view.View.dispatchPointerEvent(View.java:8357)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4778)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4644)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4225)