AsyncTask完成后,Android应用程序将关闭

时间:2014-09-04 04:39:08

标签: android json httprequest

我的应用程序到目前为止工作正常,但是当我收到信息并解析它时(基本上是在完成aysnctask时)我做了一个httprequest应用程序关闭。 log cat显示没有错误,所以我不知道发生了什么。我在另一个应用程序中使用了相同的代码,但没有出现此问题。什么是关于什么的想法?

AysncTask片段:

private class GetFreeWeek extends AsyncTask<Void, Void, Void> {



        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(LogIn.this);
            pDialog.setMessage("Please wait...");
            pDialog.setCancelable(false);
            pDialog.show();


        }

        @Override
        protected Void doInBackground(Void... arg0) {
            // Creating service handler class instance
            ServiceHandler sh = new ServiceHandler();

            // Making a request to url and getting response
            String freeWeek = sh.makeServiceCall(url, ServiceHandler.GET);

            Log.d("Response: ", "> " + freeWeek);

            if (freeWeek != null) {
                try {
                    JSONObject jsonObj = new JSONObject(freeWeek);
                    JSONArray champs = jsonObj.getJSONArray("champions");

                    for (int i=0; i < champs.length(); i++)
                    {
                        try {
                           JSONObject champion = champs.getJSONObject(i);

                           long champId = champion.getLong(TAG_ID);
                            // Pulling items from the array



                        } catch (JSONException e) {
                            // Oops
                        }
                    }



                } catch (JSONException e) {
                    e.printStackTrace();

                }
            } else {
                Log.e("ServiceHandler", "Couldn't get any data from the url");


            }




            return null;


        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            if (pDialog.isShowing())
                pDialog.dismiss();


        }
}

logcat的:

09-04 00:34:59.481: W/dalvikvm(21169): No implementation found for native           Ldalvik/system/VMRuntime;.pauseGc:(Ljava/lang/String;)I
09-04 00:34:59.481: E/ActivityThread(21169): Pause GC
09-04 00:34:59.481: E/ActivityThread(21169):  java.lang.reflect.InvocationTargetException
09-04 00:34:59.481: E/ActivityThread(21169):    at java.lang.reflect.Method.invokeNative(Native Method)
09-04 00:34:59.481: E/ActivityThread(21169):    at java.lang.reflect.Method.invoke(Method.java:515)
09-04 00:34:59.481: E/ActivityThread(21169):    at android.app.ActivityThread.pauseGC(ActivityThread.java:5525)
09-04 00:34:59.481: E/ActivityThread(21169):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
09-04 00:34:59.481: E/ActivityThread(21169):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
09-04 00:34:59.481: E/ActivityThread(21169):    at android.app.ActivityThread.access$900(ActivityThread.java:175)
09-04 00:34:59.481: E/ActivityThread(21169):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
09-04 00:34:59.481: E/ActivityThread(21169):    at android.os.Handler.dispatchMessage(Handler.java:102)
09-04 00:34:59.481: E/ActivityThread(21169):    at android.os.Looper.loop(Looper.java:146)
09-04 00:34:59.481: E/ActivityThread(21169):    at android.app.ActivityThread.main(ActivityThread.java:5602)
09-04 00:34:59.481: E/ActivityThread(21169):    at java.lang.reflect.Method.invokeNative(Native Method)
09-04 00:34:59.481: E/ActivityThread(21169):    at java.lang.reflect.Method.invoke(Method.java:515)
09-04 00:34:59.481: E/ActivityThread(21169):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
09-04 00:34:59.481: E/ActivityThread(21169):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
09-04 00:34:59.481: E/ActivityThread(21169):    at dalvik.system.NativeStart.main(Native Method)
09-04 00:34:59.481: E/ActivityThread(21169): Caused by: java.lang.UnsatisfiedLinkError:  Native method not found: dalvik.system.VMRuntime.pauseGc:(Ljava/lang/String;)I
09-04 00:34:59.481: E/ActivityThread(21169):    at dalvik.system.VMRuntime.pauseGc(Native Method)
09-04 00:34:59.481: E/ActivityThread(21169):    ... 15 more
09-04 00:34:59.501: I/PersonaManager(21169): getPersonaService() name persona_policy
09-04 00:34:59.566: I/PersonaManager(21169): getPersonaService() name persona_policy
09-04 00:34:59.611: I/PersonaManager(21169): getPersonaService() name persona_policy
09-04 00:34:59.756: D/dalvikvm(21169): GC_FOR_ALLOC freed 161K, 7% free 8554K/9184K,  paused 17ms, total 17ms
09-04 00:34:59.761: I/dalvikvm-heap(21169): Grow heap (frag case) to 9.882MB for  1127536-byte allocation
09-04 00:34:59.786: D/dalvikvm(21169): GC_FOR_ALLOC freed 3K, 7% free 9651K/10288K, paused 27ms, total 27ms
09-04 00:35:00.051: D/libEGL(21169): loaded /system/lib/egl/libEGL_mali.so
09-04 00:35:00.056: D/libEGL(21169): loaded /system/lib/egl/libGLESv1_CM_mali.so
09-04 00:35:00.061: D/libEGL(21169): loaded /system/lib/egl/libGLESv2_mali.so
09-04 00:35:00.066: E/(21169): Device driver API match
09-04 00:35:00.066: E/(21169): Device driver API version: 23
09-04 00:35:00.066: E/(21169): User space API version: 23 
09-04 00:35:00.066: E/(21169): mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Fri Mar 21 13:52:50 KST 2014 
09-04 00:35:00.121: D/OpenGLRenderer(21169): Enabling debug mode 0
09-04 00:35:00.141: D/dalvikvm(21169): GC_FOR_ALLOC freed 249K, 7% free 9916K/10632K,  paused 16ms, total 16ms
09-04 00:35:00.141: D/ProgressBar(21169): updateDrawableBounds: left = 0
09-04 00:35:00.141: D/ProgressBar(21169): updateDrawableBounds: top = 0
09-04 00:35:00.141: D/ProgressBar(21169): updateDrawableBounds: right = 96
09-04 00:35:00.141: D/ProgressBar(21169): updateDrawableBounds: bottom = 96
09-04 00:35:00.861: D/Response:(21169): > Cant show you my response ;)

1 个答案:

答案 0 :(得分:0)

//你可以在收到信息后用onPostExecute()方法完成App,活动并用AnycTask解析

private class GetFreeWeek extends AsyncTask<Void, Void, Void> {
  public static Context context;

   public GetFreeWeek(Context cont) {
   context = cont;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        if (pDialog.isShowing())
            pDialog.dismiss();

           //finished Activity after AsyncTask data
           ((Activity) context).finish();


    }
}