-5

I am developing an app which is have rest API calls and 4 tabs using page sliding tab strip but my problem is when I move tabs from left to right it's too late to display page and struck for 5 to 8 seconds why? and here i'm using fragments. my app is simply like what's app.

Thanks 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;
    }
}`

2 Answers2

3

A simple way to do that is to use AsyncTask (Background Service). recycler view in place of listviews. While the download speed depends on the connection, you can give indication to the user using the dialog or progress bar.

Saurabh Vardani
  • 1,821
  • 2
  • 18
  • 33
  • Try to Avoid blocking main Thread & unnecessary invalidations Use RelativeLayouts in a high hierarchy level Avoid Nested weights in LinearLayouts Avoid Creating Unnecessary Objects Use Static Final For Constants. – Saurabh Vardani Apr 04 '16 at 09:52
0

Your problem not about performance improvement, you just misused AsyncTask. But, as to performance, on Udacity.com you can find not bad course on this theme https://www.udacity.com/course/android-performance--ud825

Scrobot
  • 1,911
  • 3
  • 19
  • 36