gpt4 book ai didi

java - 共享首选项始终采用默认值

转载 作者:行者123 更新时间:2023-12-02 06:38:51 27 4
gpt4 key购买 nike

我的共享偏好设置总是默认,为什么会发生这种情况?这是我插入值的部分:

  holder.camera.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
RowData rd = getItem(position); //get list_row from i
System.out.println("OnClick Camera");
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
SharedPreferences prefs = (mContext).getSharedPreferences(
"com.oxtro.trustea", Context.MODE_PRIVATE);
SharedPreferences.Editor prefEditor = prefs.edit();

prefEditor.putString("crit_id_pref",String.valueOf(rd.criteria_id));


prefEditor.commit();

((Activity)mContext).startActivityForResult(takePicture, 0);


}
});

这是我检索其值的位置,该值始终作为默认值而不是所需的值获取:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK)
return;
Uri uri = data.getData();
System.out.println("File path is " + uri.toString());
String path = getRealPathFromURI(uri);
System.out.println("Real path is " + path);
imageupload= new ImageUploadManager(ChapterActivity.this);
imageupload.open();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ChapterActivity.this);
String t_critid = preferences.getString("crit_id_pref", "DEFAULT");


System.out.println("@OnActivityResult | shared pref crit id: "+t_critid);

}

最佳答案

也在您的第二个 Activity 中进行此调用,以获得结果:

 SharedPreferences prefs = (mContext).getSharedPreferences(
"com.oxtro.trustea", Context.MODE_PRIVATE);

关于java - 共享首选项始终采用默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19355703/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com