我的问题:
12-18 17:05:03.336: DEBUG/StrictMode(2112): StrictMode 策略违规;~duration=2073 毫秒:android.os.StrictMode$StrictModeDiskReadViolation:策略=23 违规=2
从工厂方法
12-18 17:05:03.336:调试/严格模式(2112):在 android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:299)
然后在我的代码中
12-18 17:05:03.336:调试/严格模式(2112):在 blah.ImageCache.getFromCache(ImageCache.java:248)
12-18 17:05:03.336:调试/严格模式(2112):
在 blah2$LoaderThread$1.handleMessage(blah.java:63)
重要的片段
类 LoaderThread 扩展 HandlerThread {
公共处理程序 mHandler;
public LoaderThread(String name) { super(name); }
@Override public void onLooperPrepared(){ mHandler = new Handler(){ public void handleMessage(Message msg) { Bitmap bit =ImageCache.getInstance().getFromCache((String)msg.obj,ImageCache.USE_DISK); } }; } }
The getFromCache method in the ImageCache class calls
bitmap = BitmapFactory.decodeFile(fLoc);
Which seems to be running on the UI thread, but it makes no sense to me. Shouldn't this be getting called on a background thread? This was the goal of using HandlerThread after all...
The LoadThread class is created in my onCreate(bundle) like this
LoaderThread loader = new LoaderThread("imgLoader")
loader.start();
and messages are passed from the UI thread via the handler
loader.mHandler.dispatchMessage(loader.mHandler.obtainMessage(args..));
I'm wondering if this has to do with the getInstance method which is static
public static synchronized ImageCache getInstance() {
if (_instance==null) { _instance = new ImageCache(); } return _instance; }