简体   繁体   中英

parse.com - Android - unable to pin large size ParseObject to local datastore

I am using Parse.com on a Google Glass device and I am trying to pin a large size ParseObject (about 50 MB) to local datastore. I've noticed that after the heap memory exceeds 10MB the pinning process is paused and no exception is thrown. I've also tried to pin sequentially a series of ParseObjects (at once) but again, the pinning process is paused when heap reaches 10MB. Sometimes it pins more objects than other times so I'm guessing that the Java GC is sometimes more hard-working than others. Please help me, or give me an alternative for storing a large object (with lots of images) internally.

1) If I understand your question correctly, you want to store images inside your phone ( so your app can retrieve later), then you may try store it in sd card:

 public static boolean storeImage(Bitmap bitmap, String filename) {

        boolean stored = false;
        String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() +
                "/myFolder";
        File dir = new File(file_path);
        if(!dir.exists())
            dir.mkdirs();
        File fileToStored = new File(dir, filename + ".png");
        try {
            FileOutputStream outputStream = new FileOutputStream(fileToStored);
            bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream);
            outputStream.flush();
            outputStream.close();
            stored = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return stored;
    }

* permission is required in Manifest file:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>  

2) After using Parse for 2 months, there is an other option for you to store image by using string in Parse database(note Image column is a string) and base64 decode/encode:

 public static Bitmap decodeBase64(String input) {
        if (input == null) return  null;
        byte[] decodedByte = Base64.decode(input, Base64.NO_WRAP);
        return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
    }

 public static String encodeTobase64(Bitmap image) {
        Bitmap immagex=image;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] b = baos.toByteArray();
        String imageEncoded = Base64.encodeToString(b, Base64.NO_WRAP);
        Log.e(TAG, "encoded Img: " + imageEncoded);
        return imageEncoded;
    }

*Note : use NO_WRAP instead of DEFAULT so that iOs app can also encode and decode your string

3) An other option to store image, I prefer this is store on server, then retrieve when you need it, you can either store on your own server, or using other famous service, I have tried Imgur API and it work great (of course, it is free if your app does not have 1,250 uploads per day or approximately 12,500 requests per day)

API documentation: https://api.imgur.com/

Android upload sample: https://github.com/AKiniyalocts/imgur-android

Feel free to comment if you know other better way. Technology changes fast!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM