Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. How download picture

How download picture

Scheduled Pinned Locked Moved Android
questioncsharpjavagraphicsperformance
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andy_Bell
    wrote on last edited by
    #1

    Good evening. I try to download picture form url and insert in Image View. I use this code to do it:

    public Bitmap getBitmapFromURL(String src) {
    Bitmap myBitmap = null;
    try {
    java.net.URL url = new java.net.URL(src);
    HttpURLConnection connection = (HttpURLConnection) url
    .openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    myBitmap = BitmapFactory.decodeStream(input);
    return myBitmap;
    } catch (IOException e) {
    e.printStackTrace();
    return null;
    }
    }

    I just want to ask you, there is problem to do so, or is it inefficient? Closing this application, remains the downloaded picture remains in memory? If I want to free memory resource, how can I cancel this files (accumulated in time)?

    L 1 Reply Last reply
    0
    • A Andy_Bell

      Good evening. I try to download picture form url and insert in Image View. I use this code to do it:

      public Bitmap getBitmapFromURL(String src) {
      Bitmap myBitmap = null;
      try {
      java.net.URL url = new java.net.URL(src);
      HttpURLConnection connection = (HttpURLConnection) url
      .openConnection();
      connection.setDoInput(true);
      connection.connect();
      InputStream input = connection.getInputStream();
      myBitmap = BitmapFactory.decodeStream(input);
      return myBitmap;
      } catch (IOException e) {
      e.printStackTrace();
      return null;
      }
      }

      I just want to ask you, there is problem to do so, or is it inefficient? Closing this application, remains the downloaded picture remains in memory? If I want to free memory resource, how can I cancel this files (accumulated in time)?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Andy_Bell wrote:

      Closing this application, remains the downloaded picture remains in memory?

      Only until the Android OS removes the application from memory. You could save space by immediately saving the bitmap on disk and only loading it into memory when you want to display it. Resources will get freed when the Bitmap object goes out of scop or is otherwise disposed.

      A 1 Reply Last reply
      0
      • L Lost User

        Andy_Bell wrote:

        Closing this application, remains the downloaded picture remains in memory?

        Only until the Android OS removes the application from memory. You could save space by immediately saving the bitmap on disk and only loading it into memory when you want to display it. Resources will get freed when the Bitmap object goes out of scop or is otherwise disposed.

        A Offline
        A Offline
        Andy_Bell
        wrote on last edited by
        #3

        Ok so unistalling my application, user can completly removed images downloaded. I have another question about. Where is the folder that contains those files?

        L 1 Reply Last reply
        0
        • A Andy_Bell

          Ok so unistalling my application, user can completly removed images downloaded. I have another question about. Where is the folder that contains those files?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Andy_Bell wrote:

          Where is the folder that contains those files?

          All depends where you save them. There was an excellent article about storage handling here on CodeProject, but the author has removed it. I guess you will need to do some searching for yourself to find something similar.

          A 1 Reply Last reply
          0
          • L Lost User

            Andy_Bell wrote:

            Where is the folder that contains those files?

            All depends where you save them. There was an excellent article about storage handling here on CodeProject, but the author has removed it. I guess you will need to do some searching for yourself to find something similar.

            A Offline
            A Offline
            Andy_Bell
            wrote on last edited by
            #5

            I haven't save file, I use only code attached in previous post. What I've been doing is connecting with HttpURLConnection at url of the image, downloading file and reading input stream. I think, doing in this way, I have a temp copy of image file stored in Android folder, but I don't know what it is.Isn't it? Thank you!

            L 1 Reply Last reply
            0
            • A Andy_Bell

              I haven't save file, I use only code attached in previous post. What I've been doing is connecting with HttpURLConnection at url of the image, downloading file and reading input stream. I think, doing in this way, I have a temp copy of image file stored in Android folder, but I don't know what it is.Isn't it? Thank you!

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Doing it this way the file only exists in virtual storage. As soon as the Bitmap object goes out of scope (e.g the object is disposed) then the data is destroyed.

              A 1 Reply Last reply
              0
              • L Lost User

                Doing it this way the file only exists in virtual storage. As soon as the Bitmap object goes out of scope (e.g the object is disposed) then the data is destroyed.

                A Offline
                A Offline
                Andy_Bell
                wrote on last edited by
                #7

                Wonderful. Just another curiosity, if I can... If I start thread with Thread instance and Run method, how can I kill this and, if it's required, restarting when it's required. Can I use thread.destroy() ?

                L D 2 Replies Last reply
                0
                • A Andy_Bell

                  Wonderful. Just another curiosity, if I can... If I start thread with Thread instance and Run method, how can I kill this and, if it's required, restarting when it's required. Can I use thread.destroy() ?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Sorry, not sure; I have not done much with Threads on Android.

                  A 1 Reply Last reply
                  0
                  • L Lost User

                    Sorry, not sure; I have not done much with Threads on Android.

                    A Offline
                    A Offline
                    Andy_Bell
                    wrote on last edited by
                    #9

                    No matter, I open another discussion. Thanks, you've been helpful!

                    1 Reply Last reply
                    0
                    • A Andy_Bell

                      Wonderful. Just another curiosity, if I can... If I start thread with Thread instance and Run method, how can I kill this and, if it's required, restarting when it's required. Can I use thread.destroy() ?

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      I would be inclined to use AsyncTask instead. It's easily stoppable (without corrupting other areas).

                      "One man's wage rise is another man's price increase." - Harold Wilson

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups