json - android - slow starting new Activity -


second activity in project starts slow, , don't know how fix it. how works (everything's in oncreate()): firstly get-request page json:

try {         defaulthttpclient hc = new defaulthttpclient();         responsehandler<string> res = new basicresponsehandler();         httpget getmethod = new httpget(url);         string response = hc.execute(getmethod, res);         resstr = response.tostring();     } catch (exception e) {         system.out.println("exp=" + e);     } 

i know methods here deprecated, don't know how make more optimized. result returns string json array of 32 objects. fill 6 arrays pass them arrayadapter filling listview. methods of getting different types of data looks this:

public static string getwantedtype(string resstr, int num) {     string jsonvalues = "";     try {         jsonarray json_array = new jsonarray(resstr);         jsonobject json_data = json_array.getjsonobject(num);         jsonvalues = json_data.getstring("wanted_type");     } catch (jsonexception e) {         e.printstacktrace();     }     return jsonvalues; } 

maybe should have created json_array 1 time outside filling arrays , pass methods jsonarray, not string - don't know if influence speed. in arrayadapter seems right, i'm using viewholder , scrolling excelent. unlike starting activity.

how make better , more optimized?

first, don't operations in oncreate() , prefer in onresume()

second, server call should in background thread using async , use result displaying user.

if don't want call multiple times api data during onresume() , onpause(), can consume result of data in array or , when onresume() call, can check whether has data, load it, else fetch server.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -