动态壁纸 - “设置壁纸” - 需要事件来清除内存

发布于 2024-12-19 17:23:50 字数 568 浏览 4 评论 0原文

我创建了一个动态壁纸,它通过在数组中存储 70 个左右的图像来显示动画,然后一次显示它们以创建动画。我使用了CubeEngine的结构来设计它。在大多数情况下它是有效的。

当我第一次选择壁纸时,它会加载数组并显示动画。然后,当我单击“设置壁纸”按钮时,我收到“OutOfMemoryError:位图大小超出虚拟机预算”。我添加了 bitmap.recycle() 调用来尝试解决此问题。

我已将 Log.d 放入所有事件中,以尝试了解事件的流程。看起来是当点击“设置壁纸”按钮时,流程直接进入构造函数。

onDestroy 事件或 onSurfaceChanged 事件不会被触发,也不会触发除 onTouchEvent 之外的任何其他事件。

因此,我的原始图像数组位于内存中,当它执行构造函数时,它会尝试加载另一个包含图像的数组,但内存不足。

当他们单击“设置壁纸”按钮时,我找不到将逻辑放入其中以清除原始数组的事件。

有没有办法向“设置壁纸”按钮添加逻辑,或者是否有另一个事件可以添加到我的代码中,我应该能够做到这一点?

我见过其他人有这个问题,但没有看到解决方案。

任何建议将不胜感激。

I've created a Live Wallpaper that displays an animation by storing 70 or so images in an array and then displays them one at time to create the animation. I used the structure of the CubeEngine to design it. For the most part it works.

When I first select the wallpaper, it loads the array and displays the animation. Then when I click the "Set Wallpaper" button I get an "OutOfMemoryError: bitmap size exceeds VM Budget". I've added the bitmap.recycle() calls to try to resolve this.

I've put Log.d in all of the events to try to understand the flow of events. What it looks like is when the "Set Wallpaper" button is tapped, the flow goes straight to the Constructor.

The onDestroy event or the onSurfaceChanged events are not triggered, nor is any other event, except the onTouchEvent.

So my original array of images is in memory and when it executes the Constructor it attempts to load another array with images and runs out of memory.

I can not find an event to put logic into to clear out my original array when they click the "Set Wallpaper" button.

Is there a way to add logic to the "Set Wallpaper" button or is there another event I can add to my code where I should be able to do this?

I've seen others have this problem but have not seen a solution.

Any suggestions will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万水千山粽是情ミ 2024-12-26 17:23:50

如果您想要进行任何加载或卸载,您可以通过重写 onVisibilityChanged(booleanvisible) 来检测 WallpaperService.Engine 的可见性何时发生变化。
当可见性发生变化时,您还应该恢复或暂停 GlSurfaceView。

您可以在此处找到更多信息:
http://developer.android.com/参考/android/service/wallpaper/WallpaperService.Engine.html#onVisibilityChanged(boolean)
http://developer.android.com/reference/android/opengl/GLSurfaceView.html
请参阅活动生命周期

If you want to do any loading or unloading, you can detect when the visibility of the WallpaperService.Engine change by overriding onVisibilityChanged(boolean visible).
You should also Resume or Pause your GlSurfaceView when the visibility change.

You can find more information here :
http://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine.html#onVisibilityChanged(boolean)
http://developer.android.com/reference/android/opengl/GLSurfaceView.html
see Activity Life-Cycle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文