在我的壁纸偏好活动中,在复选框偏好和列表偏好中,有一个意图为背景启动图像选择器。选择图像时,onSharedPreference 没有触发,我发现只有图像选择器意图不会触发 sharedpreference 更改。那么如何手动触发呢?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
Bitmap bitmap;
switch (requestCode) {
case REQUEST_CODE_GALLERY:
try {
InputStream inputStream = getContentResolver().openInputStream(data.getData());
FileOutputStream fileOutputStream = new FileOutputStream(mFileTemp);
copyStream(inputStream, fileOutputStream);
fileOutputStream.close();
inputStream.close();
startCropImage();
} catch (Exception e) {
Log.e("xxx", "Error while creating temp file", e);
}
break;
case REQUEST_CODE_CROP_IMAGE:
String path = data.getStringExtra(CropImage.IMAGE_PATH);
if (path == null) {
return;
}
bitmap = BitmapFactory.decodeFile(mFileTemp.getPath());
imagePreference.setSummary(path);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("imageDb", path);
editor.commit();
break;
}
super.onActivityResult(requestCode, resultCode, data);
}