2014-09-04 19 views
0

我的應用程序目前工作正常,但是當我創建httprequest時,應用程序在我收到信息並解析它(基本上是在完成aysnctask時)後關閉。日誌貓顯示沒有錯誤,所以我不知道發生了什麼。我在另一個應用中使用了相同的代碼,並沒有這個問題。任何想法是什麼事情?AysncTask完成後關閉Android應用程序

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 ;) 
+0

解析發佈你'AsyncTask'代碼 – 2014-09-04 04:43:02

+0

@SpringBreaker我更新了我的代碼,包括我的AsynceTask代碼片段代碼,儘可能多地顯示出來。 – ChonBonStudios 2014-09-04 04:46:28

+0

我試圖打電話給jni,對吧? – 2014-09-04 04:49:17

回答

0

//你可以接到信息後完成應用程序,在onPostExecute()方法的活動,並與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(); 


    } 
} 
+0

這是我想要的相反效果,應用程序已經做了,但是我沒有實現這個功能,我希望活動持續下去,但是在我運行它之後關閉應用程序,異步任務結束。 – ChonBonStudios 2014-09-04 07:53:31

相關問題