2012-10-10 1 views
0
private void runDialog(final int seconds){ 
     new Thread(new Runnable(){ 
      public void run(){ 
      try { 
        Thread.sleep(seconds * 1000); 
        progressDialog.dismiss(); 
      runOnUiThread(new Runnable() 
      { 
       public void run() 
       { 
         // Your Alert Code 
         AlertDialog connection = new AlertDialog.Builder(
           NewsScreenActivity.this) 
           .setTitle("No Network Found") 
           .setMessage(
             "service unavailable, please try again later") 
           .setPositiveButton("Ok", 
             new DialogInterface.OnClickListener() { 

              public void onClick(DialogInterface dialog, 
                int whichButton) { 

               finish(); 
             //  progressDialog.dismiss(); 
              } 
             }).create(); 

         connection.show(); 
       } 
      }); 

      }catch (InterruptedException e) { 
       Log.i("=================== Connection TimeO5555555555", "======"); 
      // Toast.makeText(getBaseContext(), "service unavailable, please try again later", Toast.LENGTH_SHORT).show(); 
      e.printStackTrace(); 
      } 
      } 
     }).start(); 
    } 

(일반적으로 파괴 된 당신의 (a 대화 또는 토스트 또는 다른 종속 항목을 작성하여 명시 적 중 하나, 또는) 컨텍스트에 대한 참조를 들고있다TokenException : 창을 추가 할 수 없습니까?

10-10 17:55:13.299: E/AndroidRuntime(11643): FATAL EXCEPTION: main 
    10-10 17:55:13.299: E/AndroidRuntime(11643): android.view.WindowManager$BadTokenException: Unable to add window -- token [email protected] is not valid; is your activity running? 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at android.view.ViewRoot.setView(ViewRoot.java:528) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at android.view.Window$LocalWindowManager.addView(Window.java:424) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at android.app.Dialog.show(Dialog.java:241) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at com.MariTimeGlobalNews.NewsScreenActivity$7$1.run(NewsScreenActivity.java:587) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at android.os.Handler.handleCallback(Handler.java:587) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at android.os.Handler.dispatchMessage(Handler.java:92) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at android.os.Looper.loop(Looper.java:123) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at android.app.ActivityThread.main(ActivityThread.java:3729) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at java.lang.reflect.Method.invokeNative(Native Method) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at java.lang.reflect.Method.invoke(Method.java:507) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632) 
    10-10 17:55:13.299: E/AndroidRuntime(11643): at dalvik.system.NativeStart.main(Native Method) 
+0

은 ... NewsScreenActivity.this.runOnUiThread (새의 Runnable()를 시도하는 대신 runOnUiThread (새의 Runnable() .. –

+0

감사 @imran 칸하지만 동일한 오류 ... – Android

답변

0

오류 당신이 사용하고 있기 때문에 onCreateDialog 또는 Activity가 소멸되었을 때 파괴되지 않은 다른 프로세스로 Activity 전달)