Android Photo Wall application, no amount of pictures are not afraid to crash

Source: Internet
Author: User

Photo wall This kind of function is quite common now, in many applications you can often see the shadow of the picture wall. Its design is actually very simple, with a GridView control as a "wall", and then along with the GridView rolling a picture affixed to the "wall", these photos can be stored on the phone locally, can also be downloaded from the Internet. To make an application similar to this one, there is a very important question to consider when the picture resources should be released. Because with the GridView scrolling, the load of pictures may be more and more, if there is no reasonable mechanism for the release of the picture, then when the picture reached a certain limit, the program will inevitably crash.

Today, the implementation of our photo wall application focuses on how to prevent the program from collapsing because of too many pictures. The main core algorithm uses the LRUCache class provided in Android, which is provided in version 3.1, and you need to import a ANDROID-SUPPORT-V4 jar package if you are developing it in an earlier version of Android.

For detailed explanation of LRUCache usage, you can refer to the Android high efficient loading and mapping scheme to effectively avoid program oom.

So let's start with a new Android project called Photowalldemo, where I'm using the Android 4.0 API.

The first question to consider is, where do we collect so many pictures? Here I have from Google's official demo to take out the image source, we will download the images from these URLs, the code is as follows:

public class Images {public final static string[] Imagethumburls = new string[] {"Https://lh  
            6.googleusercontent.com/-55osaww3x0q/urquutcfr5i/aaaaaaaaabs/rwlj1rukryi/s160-c/a%252520photographer.jpg ", "Https://lh4.googleusercontent.com/--dq8nirp7w4/urquvgmxvgi/aaaaaaaaabs/-gnulqfnnba/s160-c/a%252520song% 252520of%252520ice%252520and%252520fire.jpg "," https://lh5.googleusercontent.com/-7qZeDtRKFKc/URquWZT1gOI/ aaaaaaaaabs/hqwgteynxsg/s160-c/another%252520rockaway% 252520sunset.jpg "," https://lh3.googleusercontent.co m/--l0km39l5j8/urquxhgcdni/aaaaaaaaabs/3zrsjnrsomq/s160-c/antelope%252520butte.jpg "," Https://lh6.googleus Ercontent.com/-8ho-4vifnlw/urquznsfgti/aaaaaaaaabs/wt8jvitf7vw/s160-c/antelope%252520hallway.jpg "," https:  
            lh4.googleusercontent.com/-wiuwgvcu3qw/urqubrvcj4i/aaaaaaaaabs/yvbwggjwdiq/s160-c/antelope%252520walls.jpg ", "Https://lh6.googleusercontent.com/-ubmlbpelvoq/urquccdv0ki/aaaaaaaaabs/idnhr2vqoqs/s160-c/apre%2525cc%252580s%252520la% 252520Pluie.jpg ", "https://lh3.googleusercontent.com/-s-AFpvgSeew/URquc6dF-JI/AAAAAAAAAbs/Mt3xNGRUd68/s160-c/Backlit% 252520cloud.jpg "," https://lh5.googleusercontent.com/-bvmif9a9yoq/urquea3hehi/aaaaaaaaabs/rcr6wyeqtao/s160 -c/bee%252520and%252520flower.jpg "," https://lh5.googleusercontent.com/-n7mdm7I7FGs/URqueT_BT-I/AAAAAAAAAb S/9mymxlmpsao/s160-c/bonzai%252520rock%252520sunset.jpg "," https://lh6.googleusercontent.com/-4CN4X4t0M1k/ Urqufpozwzi/aaaaaaaaabs/8wk41lg1kps/s160-c/caterpillar.jpg "," https://lh3.googleusercontent.com/-RrFnVC8xQ Eg/urqufdrlbai/aaaaaaaaabs/s69wyy_fl1e/s160-c/chess.jpg "," Https://lh5.googleusercontent.com/-WVpRptWH8Yw/UR qugh-qmdi/aaaaaaaaabs/e-mgbgtluwu/s160-c/chihuly.jpg "," https://lh5.googleusercontent.com/-0BDXkYmckbo/U Rquhkfw84i/aaaaaaaaabs/ogqthctk2jq/s160-c/cloSed%252520door.jpg "," https://lh3.googleusercontent.com/-PyggXXZRykM/URquh-kVvoI/AAAAAAAAAbs/hFtDwhtrHHQ/s 160-c/colorado%252520river%252520sunset.jpg "," https://lh3.googleusercontent.com/-ZAs4dNZtALc/URquikvOCWI/ Aaaaaaaaabs/dxz4h3dll1y/s160-c/colors%252520of%252520autumn.jpg "," https://lh4.googleusercontent.com/-Gztn Weiimz8/urqukvcu7bi/aaaaaaaaabs/jo2hjv6mz6m/s160-c/countryside.jpg "," https://lh4.googleusercontent.com/-b eg9ez9qoim/urquklz3fgi/aaaaaaaaabs/uuuv8ac2bae/s160-c/death%252520valley%252520-% 252520Dunes.jpg "," https:  
            lh6.googleusercontent.com/-ijqj8w68tee/urqulgkvfei/aaaaaaaaabs/zpxviwi_rfw/s160-c/delicate%252520arch.jpg ",  
            "Https://lh5.googleusercontent.com/-oh8mmy2ieng/urqulldwehi/aaaaaaaaabs/tbdeefsaizy/s160-c/despair.jpg", "Https://lh5.googleusercontent.com/-gl0y4uiaolk/urqumc_kjbi/aaaaaaaaabs/pm1et7dn4oo/s160-c/eagle%252520fall%  
           252520sunrise.jpg ", "Https://lh3.googleusercontent.com/-hyyhd2_vxpq/urqumtja9ei/aaaaaaaaabs/waalxvkbsh0/s160-c/electric% 252520storm.jpg "," https://lh5.googleusercontent.com/-pyy_yiyjpto/urqunuohhfi/aaaaaaaaabs/azzoulnujxc/s160 -c/false%252520kiva.jpg "," https://lh6.googleusercontent.com/-PYVLVDVXYWK/URQUNWD8HFI/AAAAAAAAABS/QIMWGKFV F6i/s160-c/fitzgerald%252520streaks.jpg "," https://lh4.googleusercontent.com/-kir_uobiiqy/urquocz9sli/aaaa Aaaaabs/y4d4q8sxu4c/s160-c/foggy%252520sunset.jpg "," https://lh6.googleusercontent.com/-9lzOk_OWZH0/URquoo 4xyoi/aaaaaaaaabs/awgzhtnvcwu/s160-c/frantic.jpg "," https://lh3.googleusercontent.com/-0X3JNaKaz48/URqupH7 8wpi/aaaaaaaaabs/lhxxu_zbh8s/s160-c/golden%252520gate%252520afternoon.jpg "," https://lh6.googleusercontent.c om/-95sb5ag7abc/urqupl95rdi/aaaaaaaaabs/g73r20ivtra/s160-c/golden%252520gate%252520fog.jpg "," Https://lh3. googleusercontent.com/-jb9v6rtghhk/urqup21f-Zi/aaaaaaaaabs/64fb8qmzwxk/s160-c/golden%252520grass.jpg "," https://lh4.googleusercontent.com/-EIBGfnuL

Tii/urquqvhwari/aaaaaaaaabs/fa4mcv2u8ve/s160-c/grand%252520teton.jpg "," https://lh4.googleusercontent.com/- Womxzvmn9ny/urquq1v2aoi/aaaaaaaaabs/grj5umhl6na/s160-c/grass%252520closeup.jpg "," Https://lh3.googleusercon tent.com/-6hziehxx64q/urqurxvndqi/aaaaaaaaabs/kwmxm3o5ovi/s160-c/green%252520grass.jpg "," Https://lh5.goog leusercontent.com/-6lvb9oxtq60/urqutebfuki/aaaaaaaaabs/4f4krgecwfs/s160-c/hanging%252520leaf.jpg "," https:  
            lh4.googleusercontent.com/-zavf__52onk/urqutt_iuxi/aaaaaaaaabs/d_bcuc0thou/s160-c/highway%2525201.jpg ", "Https://lh6.googleusercontent.com/-h4srug615ra/urquul27fxi/aaaaaaaaabs/4aeqjfimsou/s160-c/horseshoe% 252520bend%252520sunset.jpg "," Https://lh4.googleusercontent.com/-JhFi4fb_Pqw/URquuX-QXbI/AAAAAAAAAbs/IXpY  Uxuweym/s160-c/horseshoe%252520bend.jpg ",
            "Https://lh5.googleusercontent.com/-uggssvfrj7g/urquueyjzgi/aaaaaaaaabs/yyibllt0tom/s160-c/into%252520the%2 52520blue.jpg "," https://lh3.googleusercontent.com/-ch7koupi7ui/urquu0ff__i/aaaaaaaaabs/r7gdmi7v_g0/s160-c /jelly%252520fish%2525202.jpg "," https://lh4.googleusercontent.com/-pwuuw6yhg8U/URquvPxR3FI/AAAAAAAAAbs/VNGk 6f-tsge/s160-c/jelly%252520fish%2525203.jpg "," https://lh5.googleusercontent.com/-GoUQVw1fnFw/URquv6xbC0 I/aaaaaaaaabs/zeuvtqq43zc/s160-c/kauai.jpg "," Https://lh6.googleusercontent.com/-8QdYYQEpYjw/URquwvdh88I/AAA Aaaaaabs/cktdy-ysfho/s160-c/kyoto%252520sunset.jpg "," https://lh4.googleusercontent.com/-vPeekyDjOE0/URq Uwzj28qi/aaaaaaaaabs/qxcyxulszrg/s160-c/lake%252520tahoe%252520colors.jpg "," https://lh4.googleusercontent.c om/-xbpxwpd4yxu/urquxwhk8ai/aaaaaaaaabs/ardpedypimy/s160-c/lava%252520from%252520the% 252520Sky.jpg "," HT Tps://lh3.googleusercontent.com/-897vxrjb6re/urquxxxd-5i/aaaaaaaaabs/j-cz4t4yviw/s160-c/leica%25252050mm%252520summilux.jpg "," htt ps://lh5.googleusercontent.com/-qsj4d4ixzgo/urquydwij1i/aaaaaaaaabs/k2pbxewehoa/s160-c/leica%25252050mm% 252520summilux.jpg "," https://lh6.googleusercontent.com/-dwlpg83vzlg/urquyltvufi/aaaaaaaaabs/g6syq8b4ysi/s 160-c/leica%252520m8%252520%252528front% 252529.jpg "," https://lh3.googleusercontent.com/-R3_EYAyJvfk/URq 

Uzqbv8ei/aaaaaaaaabs/b9xhpum3pei/s160-c/light%252520to%252520sand.jpg "," https://lh3.googleusercontent.com/- fhy5h67qpi0/urqu0cp4j1i/aaaaaaaaabs/0lg6m94z6vm/s160-c/little%252520bit%252520of% 252520Paradise.jpg "," H ttps://lh5.googleusercontent.com/-tzf_lwrcnrm/urqu0rddpoi/aaaaaaaaabs/gaj2dliux0s/s160-c/lone%252520pine% 252520sunset.jpg "," https://lh3.googleusercontent.com/-4hdpj4_dxu4/urqu046dj9i/aaaaaaaaabs/eboodtk2_uk/s16 0-c/lonely%252520rock.jpg "," Https://lh6.Googleusercontent.com/-erbf--z-w4s/urqu1ajslki/aaaaaaaaabs/xjdcdo1inzm/s160-c/longue%252520vue.jpg "," http s://lh6.googleusercontent.com/-0cxjrdjaqvc/urqu1opnzni/aaaaaaaaabs/pfb2opuu7lk/s160-c/look%252520me%252520in% 252520the% 252520eye.jpg "," https://lh3.googleusercontent.com/-D_5LNXNDN6G/URQU2TK7HVI/AAAAAAAAABS/P0DDCA 9w__y/s160-c/lost%252520in%252520a%252520field.jpg "," https://lh6.googleusercontent.com/-flsqwMrIk2Q/URqu2 4pcmji/aaaaaaaaabs/5ocih85xofm/s160-c/marshall%252520beach%252520sunset.jpg "," https://lh4.googleusercontent . com/-y4lgryevtmu/urqu28kg3gi/aaaaaaaaabs/ojxpekqtbj4/s160-c/mono%252520lake%252520blue.jpg "," Https://lh4

. googleusercontent.com/-aahajpmcgya/urqu3pildhi/aaaaaaaaabs/lctqk1sicrs/s160-c/monument%252520valley% 252520overlook.jpg "," https://lh4.googleusercontent.com/-vkxfdq83dqa/urqu31yq_bi/aaaaaaaaabs/ouogk_2ayfm/s 160-c/moving%252520rock.jpg "," https://lh5.googleusercontent.com/-cg62qippwxg/urqu4ia4vri/aaaaaaaaabs/0yodqlalcac/s160-c/napali%252520coast.jpg ", "Https://lh6.googleusercontent.com/-wdgrp5pmmjq/urqu5pzvn7i/aaaaaaaaabs/m0abecdpxe4/s160-c/one%252520wheel.jpg "," https://lh6.googleusercontent.com/-6ws5docguoa/urqu5qx1ugi/aaaaaaaaabs/gimw2ixpvry/s160-c/open%252520s Ky.jpg "," https://lh6.googleusercontent.com/-U8ehkj8g8gq/urqu55sm6yi/aaaaaaaaabs/lixx_gltdmi/s160-c/orange %252520sunset.jpg "," https://lh6.googleusercontent.com/-74z5qj4btde/urqu6lsrjri/aaaaaaaaabs/xzmvkw90szq/s1 60-c/orchid.jpg "," https://lh6.googleusercontent.com/-leqe4h6tepe/urqu6t_lski/aaaaaaaaabs/zvgykoea_qy/s160 -c/over%252520there.jpg "," HTTPS://LH5.GOOGLEUSERCONTENT.COM/-CAUH-53JH2M/URQU66V_USI/AAAAAAAAABS/EUCWWQCL Fkq/s160-c/plumes.jpg "," Https://lh3.googleusercontent.com/-eDLT2jHDoy4/URqu7axzkAI/AAAAAAAAAbs/iVZE-xJ7lZ  
     S/s160-c/rainbokeh.jpg ",       "Https://lh5.googleusercontent.com/-j1nlqefiyco/urqu8l1cgci/aaaaaaaaabs/aqzkgx66zli/s160-c/rainbow.jpg", "Https://lh5.googleusercontent.com/-drnqmk0t4vu/urqu8xyn9yi/aaaaaaaaabs/lgvf_592wlu/s160-c/rice% 252520fields.jpg "," https://lh3.googleusercontent.com/-hwh1v3eogcq/urqu8qoakwi/aaaaaaaaabs/iljrjrnbjgw/s16 0-c/rockaway%252520fire%252520sky.jpg "," Https://lh5.googleusercontent.com/-wjV6FQk7tlk/URqu9jCQ8sI/AAAAAAAA Abs/ryyupdo-c9o/s160-c/rockaway%252520flow.jpg "," https://lh6.googleusercontent.com/-6cAXNfo7D20/URqu-Bd Zgpi/aaaaaaaaabs/omsyllzjqwo/s160-c/rockaway%252520sunset%252520sky.jpg "," https://lh3.googleusercontent.com /-sl8fpgps-re/urqu_bokfgi/aaaaaaaaabs/dg2fv-jxoeg/s160-c/russian%252520ridge%252520sunset.jpg "," https://l h6.googleusercontent.com/-gvty36mmbig/urqu_q91lki/aaaaaaaaabs/3cifmbcy5ma/s160-c/rust%252520knot.jpg "," HT tps://lh6.googleusercontent.com/-GheimuhQjbe/urqu_fkfvli/aaaaaaaaabs/axuejeqam7q/s160-c/sailing%252520stones.jpg "," https://lh3.googleusercontent.co m/-hbbyzjtowgc/urqu_ycpiri/aaaaaaaaabs/nadjuxngjye/s160-c/seahorse.jpg "," https://lh3.googleusercontent.co M/-iwi6-i6iexy/urqvayzhsvi/aaaaaaaaabs/5etwl4qxsfe/s160-c/shinjuku%252520street.jpg "," Https://lh6.googleu sercontent.com/-amhnystm_my/urqvalb5koi/aaaaaaaaabs/pfcfgzlksn0/s160-c/sierra%252520heavens.jpg "," https:/  
            /lh5.googleusercontent.com/-djgjepfryso/urqvbvjzrai/aaaaaaaaabs/v-f5qwpyo6s/s160-c/sierra%252520sunset.jpg ", "Https://lh4.googleusercontent.com/-z4zgic5nwdc/urqvbdewivi/aaaaaaaaabs/zrzr1vj84qa/s160-c/sin% 252520lights.jpg "," https://lh4.googleusercontent.com/-_0cyiww8ccy/urqvbz3im4i/aaaaaaaaabs/9n_wq8mhlty/s16 0-c/starry%252520lake.jpg "," https://lh3.googleusercontent.com/-a9lmoryuqua/urqvcyx_joi/aaaaaaaaabs/s7sde1  
      Bz9ci/s160-c/starry%252520night.jpg ",      "Https://lh3.googleusercontent.com/-ktlj3k858ey/urqvc_2h_bi/aaaaaaaaabs/zzebimwda_g/s160-c/stream.jpg", "Https://lh5.googleusercontent.com/-dfb7lad6rca/urqvduftwwi/aaaaaaaaabs/brhoutxtn7o/s160-c/strip% 252520sunset.jpg "," https://lh5.googleusercontent.com/-at6apgfin20/urqvdyffuzi/aaaaaaaaabs/clabcx171be/s16 0-c/sunset%252520hills.jpg "," Https://lh4.googleusercontent.com/-7-EHhtQthII/URqvEYTk4vI/AAAAAAAAAbs/QSJZo B3yjvg/s160-c/tenaya%252520lake%2525202.jpg "," https://lh6.googleusercontent.com/-8MrjV_a-Pok/URqvFC5repI/ Aaaaaaaaabs/9inktg9fbce/s160-c/tenaya%252520lake.jpg "," https://lh5.googleusercontent.com/-B1HW-z4zwao/URq Vfwyrwui/aaaaaaaaabs/8peli53bs8i/s160-c/the%252520cave%252520bw.jpg "," Https://lh3.googleusercontent.com/-PO 4e-xzkanq/urqvgrqjyki/aaaaaaaaabs/42nyadfsxag/s160-c/the%252520fisherman.jpg "," Https://lh4.googleusercont ent.com/-ILYZLZFDY7S/URQVG0YSCDI/AAAAAAAAabs/1j9edkmkxtk/s160-c/the%252520night%252520is% 252520coming.jpg "," https://lh6.googleusercontent.com/-g- K7ykkuco0/urqvhhah6fi/aaaaaaaaabs/_taqqg7t0vo/s160-c/the%252520road.jpg "," https://lh6.googleusercontent.co M/-h-aljt7ksus/urqvithqyfi/aaaaaaaaabs/ejiv35olws8/s160-c/tokyo%252520heights.jpg "," Https://lh5.googleuse Rcontent.com/-hy9k-tbs7xg/urqvijqmoxi/aaaaaaaaabs/rspmmoatskg/s160-c/tokyo%252520highway.jpg "," Https://lh 6.googleusercontent.com/-83oovmb4ozs/urqvjl0t7li/aaaaaaaaabs/c5tecz6ronm/s160-c/tokyo%252520smog.jpg "," HT tps://lh3.googleusercontent.com/-fb-jfgreefi/urqvji3exai/aaaaaaaaabs/xfyweirf4v8/s160-c/tufa%252520at% 252520night.jpg "," https://lh4.googleusercontent.com/-vngkd5z1u8w/urqvjucegpi/aaaaaaaaabs/ulxcmvcu6eu/s160 -c/valley%252520sunset.jpg "," https://lh6.googleusercontent.com/-doz5i2e2omq/urqvkmnd1ki/aaaaaaaaabs/iqf0i Sinleo/s160-c/windmill%252520sunrise.jpg ",  
            "Https://lh5.googleusercontent.com/-biyiywcj9mu/urqvkculiai/aaaaaaaaabs/jypscpljope/s160-c/windmill.jpg", "Https://lh4.googleusercontent.com/-pdt167_xrda/urqvk36mlci/aaaaaaaaabs/oi2ik9qsemi/s160-c/windmills.jpg" , "https://lh5.googleusercontent.com/-Ki_qdyx7vlu/urqvlxcb6gi/aaaaaaaaabs/n31vlz6u89o/s160-c/yet%252520ano ther%252520rockaway% 252520sunset.jpg "," https://lh4.googleusercontent.com/-e9nhz5k5mss/urqvmibzjti/aaaaa  
Aaaabs/1fv810rdnfq/s160-c/yosemite%252520tree.jpg ",}; }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.