passing image fetched from a remote source in an activity to another activity using picasso

拜拜、爱过 提交于 2019-12-12 03:35:16

问题


I'm a beginner in android development.I've a set images fetched from a URL into an Activity 'A' using Picasso, and are arranged in a GridView. Now, I want to pass the image which the user has tapped on, into an Intent. How can I pass the one of the fetched image to another activity, without having to fetch the image again.

Please help me.

Thank you.


回答1:


If you are trying to reuse an image fetched in ActivityA in ActivityB without fetching again, you don't have to do anything apart from calling

Picasso.with(context).load(url).into(imageView)

at both places.

If the url parameter is the same for both the activities, Picasso automatically fetches the image from cache(where it got stored when you called load in ActivityA) instead of making another network call.

Picasso automatically caches your image in the RAM, and uses okhttp internally to cache it in the disk. So, you don't have to pass it explicitly through an intent.

To check where it got loaded from, you can call

Picasso.with(getContext()).setIndicatorsEnabled(true).

This will put a colored flag on the top-left corner of every image.

Red means it was called fetched from the network.

Blue- disk.

Green- RAM.

In ActivityA, it should be Red since you're loading it from the network. In ActivityB, it should be Green(or blue), since you're fetching it from the cache.




回答2:


I think you need to create another imageView into ActivityB and when user click on some gridView element pass the imageUrl of element and load passed url on the ActivityB either way i think you can`t pass already loaded imageView to ActivityB without loaded image again..



来源:https://stackoverflow.com/questions/35958442/passing-image-fetched-from-a-remote-source-in-an-activity-to-another-activity-us

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!