使用WallpaperManager.getInstance(context)
和(WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE)
有什麼區別?WallpaperManager.getInstance()與getSystemService(Context.WALLPAPER_SERVICE)有什麼區別
如果我打開getInstance()
方法的源代碼,它會返回(WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE)
,所以顯然沒有區別。但根據this answer,使用getInstance()
解決了OP的問題。另外,docs建議使用getSystemService()
。
哪種方法更好,爲什麼?
靜態方法並不意味着它返回對象的同一個實例。 – lagoman