维护动态壁纸渲染器的单个实例
我有一个动态壁纸应用程序,它将多个用户选择的图像加载为位图。此过程非常占用内存,因为会加载多个位图。如果已应用动态壁纸并在动态壁纸选择器中进行预览,则应用程序会在某些手机上崩溃。我相信这是因为创建了渲染器的第二个实例,它使用了所需位图内存的两倍,从而导致崩溃。
如何阻止预览模式创建动态壁纸的新实例,而是加载现有的渲染器?
I have a live wallpaper application which loads multiple user-selected images as bitmaps. This process is very memory intensive, as multiple bitmaps are loaded. The application crashes on some phones if the live wallpaper is already applied and then also previewed in the live wallpaper picker. I believe this is because a second instance of the renderer is created, which uses twice as much bitmap memory as needed, causing a crash.
How would I stop the preview mode from creating a new instance of the live wallpaper, but instead load the already existing renderer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,并通过将位图设为静态来解决它,以便它们在实例之间共享。不要忘记在加载/解码之前检查位图是否为空,以避免不必要的处理。
I had the same problem and solved it by making the bitmaps static so that they are shared among the instances. Don't forget to check if a bitmap is null before loading/decoding it to avoid unnecessary processing.