Ich entwickle eine App, die Ruhe API-Aufrufe und 4 Tabs mit der Seite Schieberegler Streifen haben, aber mein Problem ist, wenn ich Tabs von links nach rechts bewegt, es ist zu spät, um Seite anzuzeigen und schlug für 5 bis 8 Sekunden warum? und hier verwende ich Fragmente. Meine App ist einfach wie die App.Wie kann ich meine App beschleunigen?
Dank in advance.`
class GetTasks extends AsyncTask<String, Void, String> {
protected void onPreExecute() {
progressBar.setVisibility(View.VISIBLE);
}
protected void onPostExecute(String response) {
progressBar.setVisibility(View.GONE);
if (response != null && response.length() > 0) {
try {
JSONArray jsonArray = new JSONArray(response);
if (jsonArray != null && jsonArray.length() > 0) {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObj = jsonArray.getJSONObject(i);
Gson gson = new Gson();
Task task = gson.fromJson(jsonObj.toString(),Task.class);
tasklist.add(task);
}
}else{
nodata.setVisibility(View.VISIBLE);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
nodata.setVisibility(View.VISIBLE);
}
Collections.reverse(tasklist);
ListAdapter adapter = new ListAdapter(tasklist);
list_view.setAdapter(adapter);
}
@Override
protected String doInBackground(String... params) {
try {
String response = Util.excuteGet(params[0]);
return response;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}`
Sie tun zu viele Dinge auf dem Hauptthread. – EpicPandaForce
http://stackoverflow.com/questions/15472383/how-can-i-run-code-on-a-background-thread-on-android – Kenn
siehe unten beantworten. –