画像をダウンロードしてSDカードに保存するアプリを開発しています。SDカードと対話するクラスは次のようになります...
public class SDCardImageManagerImp implements SDCardImageManager {
private Context context;
@Inject
public SDCardImageManagerImp(Context context) {
this.context = context;
}
@Override
public void saveToSDCard(String id, Bitmap bitmap) throws FileNotFoundException {
FileOutputStream outputStream = context.openFileOutput(id, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
}
@Override
public Bitmap getImage(String id) throws FileNotFoundException {
return BitmapFactory.decodeStream(context.openFileInput(id));
}
@Override
public void deleteImage(String id) {
context.deleteFile(id);
}
}
複数のスレッドでディスクへの書き込みを読み取るとパフォーマンスが低下する可能性があるため、このクラスはシングルトンです。ただし、データをダウンロードしてこのクラスに送信する複数のスレッドがあります。だから私の質問は、このクラスのすべてのメソッドに同期化されたキーが機能する必要があるということですか?