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

  • Home
  • SEARCH
  • 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 8909287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:23:30+00:00 2026-06-15T03:23:30+00:00

My activity works fine using thread but when there is 10 or more images

  • 0

My activity works fine using thread but when there is 10 or more images to fetch from web server database, it takes lot of time. From googling, I have seen that asynctask is a better option, but I am not able to implement it. Here is my thread class

public class Ongoing extends Activity implements OnItemClickListener{

InputStream is;
ProgressDialog pd;
public int limit=0;
String F_NAME[]=new String[1000];
String F_ID[]=new String[1000];
String F_IMG[]=new String[1000];
String F_DESC[]=new String[1000];
String F_DOWN[]=new String[1000];
ListView lv1;
ArrayList<ItemDetails> image_details;

@Override

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  int SDK_INT = android.os.Build.VERSION.SDK_INT;

  if (SDK_INT>8)
  {

  StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

  StrictMode.setThreadPolicy(policy); 

  }

      setContentView(R.layout.submenu);

    lv1 = (ListView) findViewById(R.id.listV_main);


    lv1.setOnItemClickListener(this) ;
    pd=new ProgressDialog(this);
    pd.setTitle("Please wait");
    pd.setMessage("Loading....");
    pd.setCancelable(false);
    pd.show();

    new Thread(new Runnable()
    {
        @Override
        public void run()
        {

            GetSearchResults();


       //   hanlder.sendEmptyMessage(1);

             runOnUiThread(new Runnable() {
                 @Override
                 public void run() {
                     lv1 = (ListView) findViewById(R.id.listV_main);
                     adb=new ItemListBaseAdapter(Ongoing.this, results);
                     lv1.setAdapter(adb);
                     pd.cancel();
                 }
             });

        }
    }).start();

 }  
ItemListBaseAdapter adb;  
   private ArrayList<ItemDetails> results = new ArrayList<ItemDetails>();
private ArrayList<ItemDetails> GetSearchResults()
{
 try{ 
 String result = "";
try{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(D.url+"abc.php");
    //httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost); 
    HttpEntity entity = response.getEntity();
    is = entity.getContent();
    Log.e("log_tag", "connection success ");

   }catch(Exception e){
    Log.e("log_tag", "Error in http connection "+e.toString());


   }

 try{
  BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso- 88591"),8);
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");

    }
    is.close();

    result=sb.toString();
  }catch(Exception e){
   Log.e("log_tag", "Error converting result "+e.toString());

  }

  try{


    JSONArray jArray = new JSONArray(result);
    int arrayLength=jArray.length();
    limit=arrayLength;
    for(int i=0;i<arrayLength;i++){
           JSONObject json_data = jArray.getJSONObject(i);

           F_NAME[i]=json_data.getString("F_NAME");
           F_DESC[i]=json_data.getString("F_DESC");
           F_ID[i]="ongopro"+json_data.getString("F_ID");
           F_IMG[i]=json_data.getString("F_IMG");
           F_DOWN[i]=json_data.getString("F_DOWNLOAD");
    }
   }
    catch(JSONException e){
        Log.e("log_tag", "Error parsing data "+e.toString());

  }                


    for(int j=0;j<limit;++j)
    {


         ItemDetails item_details = new ItemDetails();
        item_details.setName(F_NAME[j]);
        item_details.setItemDescription(F_DESC[j]);
        item_details.setImgUrl(F_IMG[j]);
        item_details.setLoc(F_DOWN[j]);
        results.add(item_details);
    }

 }
 catch(Exception e){
     Log.e("log_tag", "no msg sent "+e.toString());
     hanlder.sendEmptyMessage(2);

}
 return results;

}
@Override
 public void onItemClick(AdapterView<?> parent, View view,
      int position, long id) {
data.proj=F_DOWN[position];
 data.table=F_ID[position];
 data.flatname=F_NAME[position];

Intent newActivity = new Intent(view.getContext(),homescreen.class);     
    startActivity(newActivity);
  }}

Below is the code in asynctask(but it not working,please edit this )

public class Ongoing extends Activity implements OnItemClickListener{

InputStream is;
ProgressDialog pd;
public int limit=0;
String F_NAME[]=new String[1000];
String F_ID[]=new String[1000];
String F_IMG[]=new String[1000];
String F_DESC[]=new String[1000];
String F_DOWN[]=new String[1000];
ListView lv1;
ArrayList<ItemDetails> image_details;
ItemListBaseAdapter adb;
@Override

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  int SDK_INT = android.os.Build.VERSION.SDK_INT;

  if (SDK_INT>8)
  {

   StrictMode.ThreadPolicy policy = new    StrictMode.ThreadPolicy.Builder().permitAll().build();

  StrictMode.setThreadPolicy(policy); 

  }

      setContentView(R.layout.submenu);

    lv1 = (ListView) findViewById(R.id.listV_main);


    lv1.setOnItemClickListener(this) ;
    pd=new ProgressDialog(this);
    pd.setTitle("Please wait");
    pd.setMessage("Loading....");
    pd.setCancelable(false);
    pd.show();

    load task=new load();
    task.execute();



 }  


public class load extends AsyncTask<Void, Void , ArrayList<ItemDetails>>
{
    public ArrayList<ItemDetails> results = new ArrayList<ItemDetails>();
    @Override
    protected ArrayList<ItemDetails> doInBackground(Void... params) {

        String result = "";
        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(D.url+"abc.php");
            //httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost); 
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
            Log.e("log_tag", "connection success ");

    }catch(Exception e){
            Log.e("log_tag", "Error in http connection "+e.toString());


    }
    //convert response to string
    try{
  BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");

            }
            is.close();

            result=sb.toString();
    }catch(Exception e){
           Log.e("log_tag", "Error converting result "+e.toString());


    }

    //parse json data

    try{


            JSONArray jArray = new JSONArray(result);
            int arrayLength=jArray.length();
            limit=arrayLength;
            for(int i=0;i<arrayLength;i++){
                   JSONObject json_data = jArray.getJSONObject(i);

                   F_NAME[i]=json_data.getString("F_NAME");
                   F_DESC[i]=json_data.getString("F_DESC");
                   F_ID[i]="ongopro"+json_data.getString("F_ID");
                   F_IMG[i]=json_data.getString("F_IMG")+"";
                   F_DOWN[i]=json_data.getString("F_DOWNLOAD");
            }
    }
            catch(JSONException e){
                Log.e("log_tag", "Error parsing data "+e.toString());

        }                


            for(int j=0;j<limit;++j)
            {


                 ItemDetails item_details = new ItemDetails();
                item_details.setName(F_NAME[j]);
                item_details.setItemDescription(F_DESC[j]);
                item_details.setImgUrl(F_IMG[j]);
                item_details.setLoc(F_DOWN[j]);
                results.add(item_details);
            }

         }
         catch(Exception e){
             Log.e("log_tag", "no msg sent "+e.toString());
             hanlder.sendEmptyMessage(2);

         return results;

    }
    protected void onPostExecute() {


         adb=new ItemListBaseAdapter(Ongoing.this, results);
        lv1.setAdapter(adb);
        pd.dismiss();

}
    @Override
    protected void onPreExecute() {
}}
  @Override
   public void onItemClick(AdapterView<?> parent, View view,
      int position, long id) {
data.proj=F_DOWN[position];
 data.table=F_ID[position];
 data.flatname=F_NAME[position];

Intent newActivity = new Intent(view.getContext(),homescreen.class);     
    startActivity(newActivity);
 }}
  • 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-15T03:23:31+00:00Added an answer on June 15, 2026 at 3:23 am

    check this i edited your code with asynctask

    public class Ongoing extends Activity implements OnItemClickListener{
    
    InputStream is;
    ProgressDialog pd;
    public int limit=0;
    String F_NAME[]=new String[1000];
    String F_ID[]=new String[1000];
    String F_IMG[]=new String[1000];
    String F_DESC[]=new String[1000];
    String F_DOWN[]=new String[1000];
    ListView lv1;
    ArrayList<ItemDetails> image_details;
    
    @Override
    
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      int SDK_INT = android.os.Build.VERSION.SDK_INT;
    
      if (SDK_INT>8)
      {
    
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    
      StrictMode.setThreadPolicy(policy); 
    
      }
    
          setContentView(R.layout.submenu);
    
        lv1 = (ListView) findViewById(R.id.listV_main);
    
    
        lv1.setOnItemClickListener(this) ;
    
    
       new Mytask.execute(null);
    
     }  
    ItemListBaseAdapter adb;  
       private ArrayList<ItemDetails> results = new ArrayList<ItemDetails>();
    private ArrayList<ItemDetails> GetSearchResults()
    {
     try{ 
     String result = "";
    try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(D.url+"abc.php");
        //httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost); 
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        Log.e("log_tag", "connection success ");
    
       }catch(Exception e){
        Log.e("log_tag", "Error in http connection "+e.toString());
    
    
       }
    
     try{
      BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso- 88591"),8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
    
        }
        is.close();
    
        result=sb.toString();
      }catch(Exception e){
       Log.e("log_tag", "Error converting result "+e.toString());
    
      }
    
      try{
    
    
        JSONArray jArray = new JSONArray(result);
        int arrayLength=jArray.length();
        limit=arrayLength;
        for(int i=0;i<arrayLength;i++){
               JSONObject json_data = jArray.getJSONObject(i);
    
               F_NAME[i]=json_data.getString("F_NAME");
               F_DESC[i]=json_data.getString("F_DESC");
               F_ID[i]="ongopro"+json_data.getString("F_ID");
               F_IMG[i]=json_data.getString("F_IMG");
               F_DOWN[i]=json_data.getString("F_DOWNLOAD");
        }
       }
        catch(JSONException e){
            Log.e("log_tag", "Error parsing data "+e.toString());
    
      }                
    
    
        for(int j=0;j<limit;++j)
        {
    
    
             ItemDetails item_details = new ItemDetails();
            item_details.setName(F_NAME[j]);
            item_details.setItemDescription(F_DESC[j]);
            item_details.setImgUrl(F_IMG[j]);
            item_details.setLoc(F_DOWN[j]);
            results.add(item_details);
        }
    
     }
     catch(Exception e){
         Log.e("log_tag", "no msg sent "+e.toString());
         hanlder.sendEmptyMessage(2);
    
    }
     return results;
    
    }
    @Override
     public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {
    data.proj=F_DOWN[position];
     data.table=F_ID[position];
     data.flatname=F_NAME[position];
    
    Intent newActivity = new Intent(view.getContext(),homescreen.class);     
        startActivity(newActivity);
      }
    
    
      private class MyTask extends AsyncTask
    {
    
            Dialog dialog;
    
            @Override
            protected void onPreExecute() {
                // TODO Auto-generated method stub
                super.onPreExecute();
                dialog = new Dialog(yourclass.this);
                dialog.setTitle("Please wait");
                TextView tv = new TextView(yourclass.this.getApplicationContext());
                tv.setText("Loading...");
                dialog.setContentView(tv);
                dialog.show();
            }
    
            @Override
            protected Object doInBackground(Object... params)
            {
                        GetSearchResults();
    
    
            }
    
            @Override
            protected void onPostExecute(Object result) {
                // TODO Auto-generated method stub
                super.onPostExecute(result);
                if(dialog.isShowing())
                    dialog.cancel();
                    lv1 = (ListView) findViewById(R.id.listV_main);
                         adb=new ItemListBaseAdapter(Ongoing.this, results);
                         lv1.setAdapter(adb);
                Toast.makeText(getApplicationContext(), "Loaded Succesfully", Toast.LENGTH_LONG).show();
    
    
            }
    
        }
    
    
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is important: using tabbed activity (deprecated) everything works fine with my code, this
I am using a thread and a handler in android. The app works fine
I'm using overridePendingTransition for when my activity is created and that works fine I
I have an android activity and a service implemented using aidl. Works like a
I'm working on a Android game using SurfaceView, the game works fine, so I
I am using following example to display internet images in my activity. http://developer.android.com/resources/tutorials/views/hello-gridview.html In
I created an app for playing videos. It works fine but the problem is
Hello all i have an app it works fine on API 8 but i
I have a thread using handler and messages to send data to the activity.
I'm having a rather odd issue where the menu for an activity works totally

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.