service - Android Load Feed Data along with multiple images to SQLite -


Need to download the feed from the URL and save the feed item data in the scilit. Images in some feed items may need to be downloaded and saved on the device. (A reference will be saved in sqlite) It all happens in the background No interaction is required with the UI / Main thread.

I have coded the download of feed data (JSON), parsing of GSON data (using GSOn) and saving of data base in single 'async task'. Can I have the logic of downloading images in the same asic Task? Or should I start other unsaturated work to download images inside the existing async Task? I read about handlers, should I use handler to download the image?

I am thinking of saving an image to an object in the main non-tasking task and starting another asynchronous 'onPostExecute' which downloads the pictures sequentially. Any problem with this approach ?

I think that if the above process is in progress, then what happens to the processing of the feed when the user leaves the app? If I use the 'service' then does this process continue till the user ends up leaving the app? (I read the documentation, but this part was not found). Or should I keep track of the progress of the program, such as items that have been processed and do not take action next time?

Thank you for your help.

  or   

you can store the image in your database as a BLOB

  public static byte [] urlToImageBLOB (string URL) throws IOException {httpclient = new DefaultHttpClient (); Unit = null; httpGet = new HTTPGet (URL); Response = httpclient.execute (httpGet); If (response.getStatusLine (). GetStatusCode () ==httpTitas.Sc_OK) {unit = response. Gatientity (); } Return EntityUtils.toByteArray (unit); }   

Now you need to fetch the image

  public static bitmap getImageFromBLOB (byte [] mBlob) {byte [] BB = MBBB; Return BitmapFrenchterDisadbitirerere (BB, 0, BB.Lambi); }   

to set an image

  imageView.setImageBitmap (getImageFromBLOB (cursor.getblob (object.getColumnIndex ("book_thumb")));   

or

You can also use handler for the task

  Protected Drawing Chart (string URL) {try { url = url} .replaceAll ("", "% 20"); InputStream = (InputStream) this.fetch (url); Drawable d = Drawable.createFromStream (is, "src"); Return D; } Catch (malmarmdoorleuxception E) {System.out.println (url); System.out.println ("Error on URI" + e); Return tap; } Hold (IOException e) {System.out.println ("exception:" + E); System.out.println ("Image not found"); Return tap; }} Throws safe object fetch (string address) MalformedULException, IOException {URL url = new URL (address); Object content = url.getContent (); Return content; }   

This will convert your image url into a duration on runtime, then set the gallery's image view to doubles

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -