简体   繁体   English

parse.com-Android-无法将大型ParseObject固定到本地数据存储区

[英]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. 我在Google Glass设备上使用Parse.com,并且尝试将较大的ParseObject(大约50 MB)固定到本地数据存储区。 I've noticed that after the heap memory exceeds 10MB the pinning process is paused and no exception is thrown. 我注意到,在堆内存超过10MB之后,固定过程将暂停,并且不会引发任何异常。 I've also tried to pin sequentially a series of ParseObjects (at once) but again, the pinning process is paused when heap reaches 10MB. 我也尝试依次固定一系列ParseObject(一次),但是同样,当堆达到10MB时,固定过程将暂停。 Sometimes it pins more objects than other times so I'm guessing that the Java GC is sometimes more hard-working than others. 有时它比其他时候固定更多的对象,所以我猜测Java GC有时比其他人更努力。 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: 1)如果我正确理解了您的问题,则希望将图像存储在手机中(以便您的应用稍后可以检索),然后您可以尝试将其存储在SD卡中:

 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: 2)使用Parse 2个月后,还有另一种方法供您使用Parse数据库中的字符串来存储图像(注意Image列是一个字符串)和base64解码/编码:

 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 *注意:使用NO_WRAP而不是DEFAULT,以便iOs应用程序还可以对字符串进行编码和解码

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) 3)另一种存储图像的选项,我更喜欢将其存储在服务器上,然后在需要时进行检索,您可以将其存储在自己的服务器上,或者使用其他著名的服务,我已经尝试过Imgur API,并且效果很好(当然,如果您的应用每天没有1,250次上传或每天没有大约12,500个请求,则它是免费的)

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

Android upload sample: https://github.com/AKiniyalocts/imgur-android Android上传样本: https : //github.com/AKiniyalocts/imgur-android

Feel free to comment if you know other better way. 如果您知道其他更好的方法,请随时发表评论。 Technology changes fast! 技术日新月异!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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