Search code examples
androidimageandroid-studiolarge-data-volumes

Best way to have lots of pictures in an App? Android Studio


So I am making an app that has over 200 sunset pictures (taken by myself:P). I want to display them all via android.R.layout.simple_gallery_item I tried tossing them all in the drawable folder, then bitmapping each one and drawing it on the screen, but I get an Out of memory error.

What would be the best way to store these jpg?

The only two ways I can think of are:

  • A separate zip file download from the app?
  • Drawable File? (Using bitmap wouldn't be the right way?)
  • Somehow storing them in the apk then pushing them onto the device before installing the app?(If possible, because if I am correct(which I am probably not), when building the apk, everything comes together and some files morph into one)

(PS: If can't tell, I am new to Android Developing)

Thanks!

Code:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    System.out.println("Noobs");

    ArrayList<Image> img = new ArrayList<Image>();
    for (int i=1; i<3; i++) {
        int imageResource = getResources().getIdentifier("@drawable/bm" + String.valueOf(i), null, getPackageName());
        img.add(ImageView.setImageResource(imageResource));
        System.out.println("Did Pic "+String.valueOf(i));
    }


    System.out.println("Come so far!");
    ListAdapter picAdapt = new ArrayAdapter<Image>(this, android.R.layout.simple_gallery_item, img);
    ListView picListView = (ListView) findViewById(R.id.gallery);
    picListView.setAdapter(picAdapt);

} }


Solution

  • I recommend you use picasso http://square.github.io/picasso/ or glide https://github.com/bumptech/glide
    those two help you to get and optimize your images