Note that there are some explanatory texts on larger screens.

plurals
  1. POMake a function async/threaded in android
    primarykey
    data
    text
    <p>I have an interesting question for you. I have a function in Android that interacts with the ui by loading a listview with data from a remote server. As expected, this makes my app extremely sluggish.</p> <p>With the minimum amount of code, how do I put this function on its own thread or A Sync Task, while still allowing it to perform like a normal function</p> <p>It did not be extremely efficient. I just need to do this with the minimum amount of code possible.</p> <pre><code>try { //getjson file HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(url); HttpResponse responseGet = client.execute(get); HttpEntity resEntityGet = responseGet.getEntity(); if (resEntityGet != null) { InputStream instream = resEntityGet.getContent(); BufferedReader str = new BufferedReader(new InputStreamReader( instream)); String ans = new String(""); build = new String(""); while ((ans = str.readLine()) != null) { build = build + ans; } //parse json file JSONObject total = new JSONObject(build); JSONArray prices = null; if (!total.isNull("title")){ Prices = title.getJSONArray("title"));} ArrayList&lt;data&gt; newArray = new ArrayList&lt;data&gt;(); for(int i=0;i&lt;Prices.length();i++) { JSONObject price = null; price = Prices.getJSONObject(i); data name = new data (price.getString("StoreName"),price.getString("price"),price.getString("Link")); newArray.add(name); } stockArr = new data[newArray.size()]; stockArr = newArray.toArray(stockArr); //add to listview ListView listView = (ListView) findViewById(R.id.mylist); listadapter adapter = new listadapter(this,R.layout.listview_item_row, stockArr); listView.setAdapter(adapter); } } catch(Exception e) { Toast.makeText(getApplicationContext(),e.toString(), 10).show(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload