相关疑难解决方法(0)

如何在android中使用sharedpreference存储图像?

我想使用sharedpreference在android中保存图像.我有两个活动类,当我点击第一个活动的按钮时,它将调用第二个活动,第二个活动在列表视图中显示我的首选名称,并且还将android壁纸重置为我已设置为首选壁纸的图像.第一次活动.

对于第二个活动,代码是:

public class PreferencesActivityTest extends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


            SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
            String prefName = myPrefs.getString("PREF_USERNAME", "nothing");
            String wallPaper = myPrefs.getString("PREFS_NAME", null);


            if(wallPaper != null) {

                try {

                      Bitmap bm = BitmapFactory.decodeFile("/data/misc/wallpaper/"+wallPaper);
                      Log.d(getClass().getSimpleName(),"Wallpaper name is: "+ wallPaper);
                      setWallpaper(bm);
                      Toast.makeText(this, "Wall paper has been changed." +
                                  "You may go to the home screen to view the same", Toast.LENGTH_LONG).show();
                } 

                catch (FileNotFoundException fe){
                      Log.e(getClass().getSimpleName(),"File not found");
                } catch (IOException ie) {
                      Log.e(getClass().getSimpleName()," IO Exception"); …
Run Code Online (Sandbox Code Playgroud)

android

31
推荐指数
2
解决办法
5万
查看次数

如何在Android中以共享首选项保存图像 Android中使用Image的共享首选项问题

在登录后的我的应用程序中,我必须以其他页面的共享首选项保存用户名和图像.我可以优先保存名称,但无法获得如何保存图像.

我正在尝试这样的事情 -

SharedPreferences myPrefrence;
    String namePreferance="name";

    String imagePreferance="image";

SharedPreferences.Editor editor = myPrefrence.edit();
                editor.putString("namePreferance", itemNAme);
                editor.putString("imagePreferance", itemImagePreferance);
                editor.commit();
Run Code Online (Sandbox Code Playgroud)

我试图将图像转换为对象后保存为字符串.但当我将其重新转换为位图时,我没有得到任何东西.

android image sharedpreferences

12
推荐指数
2
解决办法
3万
查看次数

如何在android中的sharedpreferences中存储位图对象

我想将位图对象存储在共享首选项和resume方法中,只需检索该对象并在后台设置它.请告诉我如何以共享首选项存储和检索它.问题是在共享首选项中我们可以将值放在String,int,bolean,long等但不是bitmao对象.请帮我解决这个问题.下面是我的代码:

    @Override
protected void onResume() {
    super.onResume();

rl_changeBackground.setBackgroundDrawable(new BitmapDrawable(getResources(),HomeSafeStaticVariables.bitmap));

    }
    }
Run Code Online (Sandbox Code Playgroud)

android bitmap

3
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×3

bitmap ×1

image ×1

sharedpreferences ×1