最近实现了背景图片的保存,使得开机后原有的背景图片依然存在,不会变成最初的一片漆黑。通过SharedPreferences的使用,使之变得很简单。
以下是代码:
SharedPreferences prefs = getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(BACKGROUND_WALLPAPER_POSITION, position); editor.commit();
SharedPreferences prefs = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE); Log.i("bruce","prefs is "+ prefs); if(prefs.getInt(BACKGROUND_WALLPAPER_POSITION, -1) > 0){ Log.i("bruce","position is "+prefs.getInt(BACKGROUND_WALLPAPER_POSITION,-1)); setBackground(prefs.getInt(BACKGROUND_WALLPAPER_POSITION, -1)); Log.i("bruce","set finished"); }