android 意图 putExtra Parsefile

android intent putExtra Parsefile

Intent intent = new Intent(mContext, SingleItemView.class);
                // Pass all data rank
                intent.putExtra("title", (meal.getTitle()));


                /*intent.putExtra("photo",
                        (meal.getParseFile("photo")));*/


                mContext.startActivity(intent);

如您所见,我正在尝试发送一个解析文件(确切地说是 returns 照片文件),并在另一个 .xml 文件上添加额外的内容以显示它,无论如何问题出在当然,我不能像 getTitle 那样使用 putExtra(String) ,并且在 SingItemView.class :

String title , b;
Meal meal = new Meal();
        // Retrieve data from MainActivity on item click event
        Intent i = getIntent();
        // Get the results of rank
        title = i.getStringExtra("title");
        b = i.getStringExtra("photo");
        // Load the results into the TextViews

        // Locate the TextViews in singleitemview.xml
        txtrank = (TextView) findViewById(R.id.title);
        txtrank.setText(title);
        ParseImageView mealImage = (ParseImageView) findViewById(R.id.icon1);
        ParseFile photoFile = meal.getParseFile("photo");
        if (photoFile != null) {
            mealImage.setParseFile(photoFile);
            mealImage.loadInBackground(new GetDataCallback() {
                @Override
                public void done(byte[] data, ParseException e) {
                    // nothing to do
                }
            });

我将图像设置到 xml 中的 praseimageview 中并进行了测试,但我没有得到预期的结果(第一个 activity 错误时来自 putextra 的图像),并且我认为 b= i.get......photo"); 不适用于 parsefile.

我的问题是,什么样的 putextra 与 ParseFile 一起使用,以及如何检索它。

通常,您希望避免将大型对象不必要地放入 Bundle 中。 我想说一个更有效、更简单的解决方案是将图像 URL 放入 Intent,然后从单个图像 Activity.

中检索它
public static final String EXTRA_IMAGE = "image";
...
i.putStringExtra(EXTRA_IMAGE, photoFile.getUrl());

在你的 SingleItemView.java

String imageUrl = i.getStringExtra(EXTRA_IMAGE);

然后您可以使用此图像 URL 加载使用 Picasso 的图像,例如:

Picasso.with(this).load(imageUrl).into(imageView);

可以找到有关毕加索的更多信息here

你可以做的是获取ParseFile的byte[],将字节存储在Bundle或Intent中,当然可以从被调用的Activity/Fragment中获取。

示例:

ParseFile mFile = meal.getParseFile("photo"); 
final byte[] mImageData = mFile.getData(); 

字节数组现在可以存储在 intent 或 bundle 中并跨应用程序组件传递。您可以通过

将 byte[] 转换回图像
final Bitmap mBitmap = BitmapFactory.decodeByteArray(mImageData, 0, mImageData.length);

ParseFile 上的 getData() 会阻塞主线程,因此您可能希望使用 GetDataInBackground 在后台执行此操作,就像您已经在上面的问题中使用的那样。您可以在

找到更多信息

https://parse.com/docs/android_guide#files