设置壁纸的Android代码耗时太长

标签 android optimization wallpaper

基本上一直在尝试通过基于位置的应用程序设置壁纸。

WallpaperManager wManager;
Bitmap bitmap;
try {
    bitmap = BitmapFactory.decodeFile(wallSrc);
    wManager = WallpaperManager.getInstance(getApplicationContext());
    wManager.setBitmap(bitmap);
}
catch (Exception e) {
    e.printStackTrace();
}

剖析代码指出该行

wManager.setBitmap(bitmap);

是这里的罪魁祸首。这似乎花费了不合理的大量时间来执行。有没有更快的机制来做同样的事情?或换一种说法 - 知道图像的路径后,将其设置为墙纸的最快方法是什么?

最佳答案

setStream可能会更快,因为您不必手动解码位图。但实际上,某些东西 必须对其进行解码...很可能您只是使用了太大的位图。

关于设置壁纸的Android代码耗时太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10149380/

相关文章:

java - 我可以在 HTML 中插入一些代码来设置 Android 壁纸吗

android - 如何从 Google Places API 获得 20 多个结果?

performance - PostgreSQL 临时表

algorithm - 有效地搜索各行中的数字对

PHP网站优化

c++ - 以编程方式在 Linux 上更改墙纸

android - 在 Android 应用程序中不使用 Facebook 或 Twitter API/SDK 的限制

Android Listview 项目选择

android - 无法解析 : com. android.support :appcompat-v7:30. 0.0

android - 如何使用getCropAndSetWallpaperIntent?