Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8898001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:29:50+00:00 2026-06-15T00:29:50+00:00

i have a problem in my app. At start i will describe how it

  • 0

i have a problem in my app. At start i will describe how it works. It send request to the server (which wasn’t created by me), and in the response i am getting JSON string ( it’s not so big average 10 records in JSONarray) there in one parameter there is URL to the picture which i download and save as a bitmap for every JSON object. To summarize i download a JSON which looks like:

{
    "id":"125", 
    "description":"desc",   
    "type":"type",  
    "state":"state",    
    "date":"2012-09-22 10:40:46.0",
    "lat":"52.321911",
    "lng":"19.464111",
    "author":"user",
    "photo":"GetImage?size=small&id=0",
    "comments":[

    ]
    }

x 10 for example, and then i download from URL “photo” image for every object. Problem lies in the time of execution, it is really really long which it should’t it is not big data. Here it is how i do this: AsyncClass that download image:

private class HttpGetImage extends AsyncTask<Object, Integer, Integer>
    {
        public boolean ready = false;
        public boolean success = false;

        @Override
        protected Integer doInBackground(Object... obj) {
            DefaultHttpClient client = new MyHttpClient(ViewEdit.this);

            HttpGet get = new HttpGet(url+photoUrl);
            HttpResponse getResponse = null;
            try {
                getResponse = client.execute(get);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                ready=true; return null;

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                ready=true; return null;

            }

            HttpEntity responseEntity = getResponse.getEntity();
            BufferedHttpEntity httpEntity = null;
            try {
                httpEntity = new BufferedHttpEntity(responseEntity);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
                ready=true; return null;

            }
            InputStream imageStream = null;
            try {
                imageStream = httpEntity.getContent();
                m_orders.get((Integer)obj[1])
                    .setOrderBitmap(BitmapFactory.decodeStream(imageStream));

                success = true;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                ready=true; return null;

            } finally {
                try {
                    imageStream.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    ready=true; return null;

                }
            }

            ready = true;
            return null;
        }
    }

and AsyncClass for jsonString:

private class HttpGetNotifications extends AsyncTask<Double, Integer, Integer>
    {
        public boolean ready = false;
        public boolean success = false;

        @Override
        protected Integer doInBackground(Double... params) 
        {
            DefaultHttpClient client = new MyHttpClient(ViewEdit.this);
            HttpGet get = new HttpGet(url + Double.toString(params[0]) + "&longitude=" + Double.toString(params[1]) + "&radius="+distance);

            HttpResponse getResponse = null;
            try {
                getResponse = client.execute(get);

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                ready=true; return null;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                ready=true; return null;
            }
            HttpEntity responseEntity = getResponse.getEntity();
            String entityContents="";
            try {
                entityContents = EntityUtils.toString(responseEntity);

                loadNotifications(entityContents);
                success = true;
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                ready=true; return null;

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                ready=true; return null;

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                ready=true; return null;

            }

            ready = true;
            return null;
        }

        public void loadNotifications(String jsonstring) throws JSONException
        {
            JSONObject jsonResponse = new JSONObject(jsonstring);

            JSONArray notifi = jsonResponse.getJSONArray("notifications");
            for (int i =0, count = notifi.length(); i <count; i++){
                //storage of data
            }       
        }
    }

Maybe you guys have an idea how can i optimize that code to reduce a time of execution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:29:51+00:00Added an answer on June 15, 2026 at 12:29 am

    Put in some profiling to find what’s taking the time. In each of your AsyncTasks:

    private long time0, time1;
    @Override protected void onPreExecute() {
        time0 = System.currentTimeMillis();
    }
    @Override protected void onPostExecute(HttpResponse response) {
        time1 = System.currentTimeMillis();
    long deltaT = (time1 - time0);
    Log.d(TAG, "Execute took "+deltaT+"ms");
    }
    

    And then go from there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem regarding Android App. I have created an application that download
I'm writing chat client/server app with c# and I have problem with threading. I
I have a strange problem with in-app billing RESTORE_TRANSACTION command. Every request RESTORE_TRANSACTION request
Here's the problem. In my app, I have 5 tabs which contains activities. In
I have a rails app and get this warning whenever I start the server
i have next problem in my application, i write app where someone will write
I have very weird problem. My app works cool on simulator but when installed
I have a curious problem: My app is distributed through ClickOnce. I recently installed
I have problem in declaring the intents on my app. I have a form
I have a Problem in my App with the Dirty Memory Size and want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.