从 android IntentService 获取 Bitmap 的最佳方式
The best way get Bitmap from android IntentService to get
我正在 Android 上开发 Web 客户端。我将 IntentService 用于 http 请求。结果,对象由 IntentService 形成,它不仅具有原始类型,而且还具有例如 Bitmap 对象字段。请告诉我在 Activity 或其他 class 中传递对象的最佳方式。
我尝试使用 ResultReceiver,但回调方法仅获取 Bundle-object:
void onReceiveResult (int resultCode, Bundle resultData)
Bundle-object只适合存放简单的类型。不建议将大型位图对象转换为字节数组。
第二条路径,将对象打包到Parcel中,设置到Intent中。然后使用 BroadcastReceiver 捕获它。如何在广播消息中发送大对象?
也许你可以只保存图像并通过OutputStream方式传递?或者只是将它保存为某个地方的静态变量?我不是Android的专家,主要是我想获得快速的应用程序。感谢您的回答!
Bundle-object is only suitable for storing simple types. Translate large Bitmap-object as byte array is not recommended.
是的,您不应该通过 Intent
传输大数据。这与数据类型无关,与大小有关。
The second path, that to pack the object in the Parcel and set in Intent. Then catch it using BroadcastReceiver. How about sending large object in Broadcast message?
一样,发消息还是需要Intent
,有限制
Or just save it as a static variable somewhere?
这会起作用,但这是一个糟糕的体系结构。如果这样做,您将始终必须考虑该静态字段,并始终确保您没有保留对不再需要的 Bitmap
的静态引用。我强烈不推荐这个。
相反,您可以将 Bitmap
对象存储到磁盘,然后在 Activity
中读取它。这是一个例子:Save bitmap to location
我正在 Android 上开发 Web 客户端。我将 IntentService 用于 http 请求。结果,对象由 IntentService 形成,它不仅具有原始类型,而且还具有例如 Bitmap 对象字段。请告诉我在 Activity 或其他 class 中传递对象的最佳方式。 我尝试使用 ResultReceiver,但回调方法仅获取 Bundle-object:
void onReceiveResult (int resultCode, Bundle resultData)
Bundle-object只适合存放简单的类型。不建议将大型位图对象转换为字节数组。
第二条路径,将对象打包到Parcel中,设置到Intent中。然后使用 BroadcastReceiver 捕获它。如何在广播消息中发送大对象?
也许你可以只保存图像并通过OutputStream方式传递?或者只是将它保存为某个地方的静态变量?我不是Android的专家,主要是我想获得快速的应用程序。感谢您的回答!
Bundle-object is only suitable for storing simple types. Translate large Bitmap-object as byte array is not recommended.
是的,您不应该通过 Intent
传输大数据。这与数据类型无关,与大小有关。
The second path, that to pack the object in the Parcel and set in Intent. Then catch it using BroadcastReceiver. How about sending large object in Broadcast message?
一样,发消息还是需要Intent
,有限制
Or just save it as a static variable somewhere?
这会起作用,但这是一个糟糕的体系结构。如果这样做,您将始终必须考虑该静态字段,并始终确保您没有保留对不再需要的 Bitmap
的静态引用。我强烈不推荐这个。
相反,您可以将 Bitmap
对象存储到磁盘,然后在 Activity
中读取它。这是一个例子:Save bitmap to location