I / Choreographer:跳过33帧!应用程序可能在其主线程上做了太多工作?

问题描述 投票:1回答:1

我相信这个错误与我没有在一个线程中运行我的JSON这一事实有关。以下是我的代码如何解决这个问题?我是否需要将其置于可运行状态,如果是这样,我该怎么做?我对线程的想法比较新,所以请帮助我吗?

 private void JsonRequestMethod() {
            mVolleySingleton = VolleySingleton.getInstance();
            //intitalize Volley Singleton request key
            mRequestQueue = mVolleySingleton.getRequestQueue();
            //2 types of requests an Array request and an Object Request
            JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, URL_API, (String) null, new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    listblogs.clear(); // here you clear the old data
                    listblogs=parseJSONResponse(response);
                    mAdapterDashBoard.setBloglist(listblogs);

                    System.out.println("it worked!!!");
                }

            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                }
            });
            mRequestQueue.add(request);
    }
private ArrayList<Blogs> parseJSONResponse(JSONArray response) {
    if (!response.equals("")) {
        ArrayList<Blogs> blogsArrayList = new ArrayList<>();
        try {
            StringBuilder data = new StringBuilder();
            for (int i = 0; i < response.length(); i++) {
                JSONObject currentQuestions = response.getJSONObject(i);
                String text = currentQuestions.getString("text");
                String points = currentQuestions.getString("points");
                String ID=currentQuestions.getString("id");
                String studentId = currentQuestions.getString("studentId");
                String DateCreated=currentQuestions.getString("created");
                long time=Long.parseLong(DateCreated.trim());
                data.append(text + "\n" + points + "\n");
                System.out.println(data);
                Blogs blogs = new Blogs();
                blogs.setId(ID);
                blogs.setMstudentId(studentId);
                blogs.setMtext(text);
                blogs.setPoints(points);
                //The dateCreated was off by 1 hour so 3600000 ms where added=1hour, (UPDATE)
                blogs.setDateCreated(getTimeAgo(time));
                System.out.println(time+"time");


                listblogs.add(blogs);

            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return listblogs;
}
android multithreading runnable
1个回答
0
投票

您正在UI线程中进行JSON解析。使用Gson将其转换为ArrayListnew Gson.fromJson(yourObject, class);将您的回复转换为POJO www.jsonschema2pojo.org/

© www.soinside.com 2019 - 2024. All rights reserved.