【发布时间】:2010-07-06 04:56:00
【问题描述】:
我有一个应用程序使用存储在 SD 卡或手机上的照片。
我有 2 个活动似乎存在某种问题(用于查看和编辑记录的活动)。单个记录通过存储提供相关照片位置的 URI 来引用照片。
当我单击我的 View 活动时,我传递了 URI,然后使用 URI 设置 ImageView。在 View Activity 中,我有一个菜单选项,可让您访问 Edit Activity。当您单击编辑时,我再次传递照片的 URI,并使用该 URI 设置 ImageView。这两个活动都可以单独显示。
但是,当我单击“后退”按钮从“编辑”移动到“查看”时,应用程序崩溃了。最初,崩溃是 OutOfMemory 异常。通过在两个活动的 onPause 函数中添加对 ((BitmapDrawable)mImageView.getDrawable()).getBitmap().recycle() 的调用,我克服了这个异常。
回收代码到位后,执行从编辑移回视图,然后在某处崩溃。我已经逐步完成了生命周期函数,并且执行成功,除了 onCreate。执行永远不会再次到达 onCreate。
我知道这与 ImageView 有关,因为当我从 View 活动的布局中删除 ImageView 时,不再发生崩溃。
这是崩溃发生时的初始堆栈跟踪:
Thread [<3> main] (Suspended (exception RuntimeException))
ViewRoot.draw(boolean) line: 1356
ViewRoot.performTraversals() line: 1097
ViewRoot.handleMessage(Message) line: 1613
ViewRoot(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4203
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 791
ZygoteInit.main(String[]) line: 549
NativeStart.main(String[]) line: not available [native method]
在这个堆栈跟踪之后,如果我在 Eclipse 中继续推动“Step Over”,堆栈跟踪最终会像这样:
Thread [<3> main] (Suspended)
ThreadGroup.uncaughtException(Thread, Throwable) line: 884
NativeStart.main(String[]) line: not available [native method]
【问题讨论】:
标签: android