0

I am working on the project in which i make the call to server and getting the information including pictures. I also have to support different dimensions of mobile and tablet. In this case, I am doing in such a way that

  1. I am getting the mobile dimensions and send to server.
  2. Based on the mobile dimensions server send the images.
  3. This technique will increase the performance to load the images in different mobile faster. And in this technique server also not have big deal to handle.

Is it good what i am doing or any other way?

Android007
  • 155
  • 11

1 Answers1

0

I found an easier way of dealing with generating different sizes of Drawables from one server image.

You should keep how ever many 'template' images within your project inside the appropriate Drawables folders, you would need as many different templates as you need different sized images, for example if you only ever have one size of image coming back from the server i.e a thumbnail image then you'll only need a thumbnail template, if you have a thumbnail and a larger display image which could come back then you'll then need two templates.

You should then get the server to only hold and send back the largest images i.e xxxhdpi. When you receive the xxxhdpi image from the server you should then re-size your image to the same height and width of your template image (which the system will choose depending on the users screen-size). This allows you to utilize the power of Drawables in Android whilst keeping your server payload low by only needing to send one image and also allows you to keep your apk light as you only need to store a few template images within your project. This can also work if you have to deal with .obb files which can't store Drawables.

Hope this helps. Let me know if you need me to explain anything in more detail or you're worried about how something would work, I've got a couple of live apps out which use this method.

vguzzi
  • 2,420
  • 2
  • 15
  • 19
  • If the large image (6 MB size) is coming from server to lower dimensions mobile which only require to show 1MB size image and i will resize it in mobile that make my performance slow at the time of getting the data from server.... – Android007 Oct 21 '15 at 09:06
  • If you're worried about that there are a few different approaches you could take to load a scaled down version of the image into memory. Read here for some more information on this - http://developer.android.com/training/displaying-bitmaps/load-bitmap.html. -- Also the speed you receive the data is more dependent on internet speed not hardware, unless your on a very old Android device. Down-scaling the image size as they're loaded would mean you would take up less memory on the phone in total. – vguzzi Oct 21 '15 at 09:10
  • But I'd give it a try, I ran into no problems with performance doing this and I was loading 100's of very high resolution images. The apps also went through thorough testing before release. What is the oldest version of Android you are supporting? – vguzzi Oct 21 '15 at 09:11
  • just i am using from sdk 11 to sdk 23..... Is what i am using is not a good way ..... – Android007 Oct 21 '15 at 09:13
  • The minimum I used was sdk 14, Android devices under sdk 14 only account for 4% of the user base, 96% of users are sdk 14 or above, I'd recommend upping it. But I do think this technique would work perfectly fine for sdk 11+ as well and would utilize Android's Drawables instead of doing it on your own. – vguzzi Oct 21 '15 at 09:19
  • My question is all about the network bandwidth. While load the image it take time. I want to reduce this delay between the user interaction and mobile. But the technique you suggesting me that handle the image at mobile side and reduce the memory of image to save. – Android007 Oct 21 '15 at 09:24
  • You should carry on doing what you're doing now then. Lots of times certain client servers can't be changed to handle this so my answer would benefit people in that situation, or if people are using an .obb. It would also be slightly easier, but your right having the server processing the images would save bandwidth, and I don't see any other possible solution, does that answer your question? – vguzzi Oct 21 '15 at 09:28