在2.0中设置桌面壁纸if(bp != null){
try {
long t1 = System.currentTimeMillis();
WallpaperManager.getInstance(ctx).setBitmap(bp);
long t2 = System.currentTimeMillis();
Log.i("aaaaa","execute time:"+(t2-t1)/1000.0+" seconds");
} catch (IOException e) {
e.printStackTrace();
}
}或if(bp != null){
try {
long t1 = System.currentTimeMillis();
G.getBaseInstance.setWallpaper(bp);
long t2 = System.currentTimeMillis();
Log.i("aaaaa","execute time:"+(t2-t1)/1000.0+" seconds");
} catch (IOException e) {
e.printStackTrace();
}
}
这两个API来设置桌面壁纸,执行的时间竟然要3至5秒....有人遇到这个问题吗?请高手解答
try {
long t1 = System.currentTimeMillis();
WallpaperManager.getInstance(ctx).setBitmap(bp);
long t2 = System.currentTimeMillis();
Log.i("aaaaa","execute time:"+(t2-t1)/1000.0+" seconds");
} catch (IOException e) {
e.printStackTrace();
}
}或if(bp != null){
try {
long t1 = System.currentTimeMillis();
G.getBaseInstance.setWallpaper(bp);
long t2 = System.currentTimeMillis();
Log.i("aaaaa","execute time:"+(t2-t1)/1000.0+" seconds");
} catch (IOException e) {
e.printStackTrace();
}
}
这两个API来设置桌面壁纸,执行的时间竟然要3至5秒....有人遇到这个问题吗?请高手解答
可以再实验下:
long t1 = System.currentTimeMillis();
WallpaperManager.getInstance(ctx).setBitmap(bp);
G.getBaseInstance.setWallpaper(bp);
long t2 = System.currentTimeMillis();
Log.i("aaaaa","execute time:"+(t2-t1)/1000.0+" seconds");
看看时间是不是2者的叠加!
我测试的结果,楼主是不是还进行了其他操作吧?换个墙纸不应该要那么长时间的。
按照你的说法,有没有方法缩短这个时间呢?
有可能,因为在2.0之前setWallpaper是在applicationcontext里直接调用的,没有使用ipc;而在2.0之后添加了WallpaperManagerService这个远程调用,可能会耗时多一些。
使用Bitmap,应该是压缩bitmap的时候耗时多了。
<code>
public void setBitmap(Bitmap bitmap) throws IOException {
try {
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null);
if (fd == null) {
return;
}
FileOutputStream fos = null;
try {
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
} finally {
if (fos != null) {
fos.close();
}
}
} catch (RemoteException e) {
}
}
</code>
public void setStream(InputStream data) throws IOException {
try {
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null);
if (fd == null) {
return;
}
FileOutputStream fos = null;
try {
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
setWallpaper(data, fos);
} finally {
if (fos != null) {
fos.close();
}
}
} catch (RemoteException e) {
}
}你可以试试调用WallpaperManager.setStream,直接设置流,看速度会不会有提升。
嗯,用setStream明显快了很多