2012-05-18 45 views
0

我是Android中的新手。請告訴我以下日誌貓錯誤意味着什麼,以及如何擺脫它?在我的應用程序中,我正在阻止不需要的調用。當我在使用我的應用程序時按下後退按鈕時,出現此錯誤。請幫助任何人都可以告訴我爲什麼我會在logcat中得到這個錯誤?

05-18 16:58:32.614: E/ActivityThread(3265): Activity com.deepthi.blockmycalls.BlockMyCallsActivity has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()? 
05-18 16:58:32.614: E/ActivityThread(3265): android.app.IntentReceiverLeaked: Activity com.deepthi.blockmycalls.BlockMyCallsActivity has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()? 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:939) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:734) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:791) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:778) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:772) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:318) 
05-18 16:58:32.614: E/ActivityThread(3265):  at com.deepthi.blockmycalls.BlockMyCallsActivity.onCheckedChanged(BlockMyCallsActivity.java:155) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.widget.CompoundButton.setChecked(CompoundButton.java:124) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.widget.CompoundButton.toggle(CompoundButton.java:86) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.widget.CompoundButton.performClick(CompoundButton.java:98) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.view.View$PerformClick.run(View.java:8816) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.os.Handler.handleCallback(Handler.java:587) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.os.Handler.dispatchMessage(Handler.java:92) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.os.Looper.loop(Looper.java:123) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
05-18 16:58:32.614: E/ActivityThread(3265):  at java.lang.reflect.Method.invokeNative(Native Method) 
05-18 16:58:32.614: E/ActivityThread(3265):  at java.lang.reflect.Method.invoke(Method.java:521) 
05-18 16:58:32.614: E/ActivityThread(3265):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
05-18 16:58:32.614: E/ActivityThread(3265):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
05-18 16:58:32.614: E/ActivityThread(3265):  at dalvik.system.NativeStart.main(Native Method) 
05-18 16:58:32.614: E/ActivityThread(3265): Activity com.deepthi.blockmycalls.BlockMyCallsActivity has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()? 
05-18 16:58:32.614: E/ActivityThread(3265): android.app.IntentReceiverLeaked: Activity com.deepthi.blockmycalls.BlockMyCallsActivity has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()? 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:939) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:734) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:791) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:778) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:772) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:318) 
05-18 16:58:32.614: E/ActivityThread(3265):  at com.deepthi.blockmycalls.BlockMyCallsActivity.onCheckedChanged(BlockMyCallsActivity.java:155) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.widget.CompoundButton.setChecked(CompoundButton.java:124) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.widget.CompoundButton.toggle(CompoundButton.java:86) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.widget.CompoundButton.performClick(CompoundButton.java:98) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.view.View$PerformClick.run(View.java:8816) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.os.Handler.handleCallback(Handler.java:587) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.os.Handler.dispatchMessage(Handler.java:92) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.os.Looper.loop(Looper.java:123) 
05-18 16:58:32.614: E/ActivityThread(3265):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
05-18 16:58:32.614: E/ActivityThread(3265):  at java.lang.reflect.Method.invokeNative(Native Method) 
05-18 16:58:32.614: E/ActivityThread(3265):  at java.lang.reflect.Method.invoke(Method.java:521) 
05-18 16:58:32.614: E/ActivityThread(3265):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
05-18 16:58:32.614: E/ActivityThread(3265):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
05-18 16:58:32.614: E/ActivityThread(3265):  at dalvik.system.NativeStart.main(Native Method) 
05-18 16:59:55.812: D/dalvikvm(3265): GC_EXPLICIT freed 4770 objects/267120 bytes in 592ms 

我的代碼:

@Override 
    public void onCheckedChanged(CompoundButton arg0, boolean arg1) { 
     // TODO Auto-generated method stub 

     CallBlocker =new BroadcastReceiver() 
     { 
      @Override 
      public void onReceive(Context context, Intent intent) { 

       Bundle extra=intent.getExtras();//new 
       telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 
       if(extra!=null)//new=== getting the blocked number 
       { 
        state=extra.getString(telephonyManager.EXTRA_STATE); 

        if(state.equals(telephonyManager.EXTRA_STATE_RINGING)) 
        { 
         number=extra.getString(telephonyManager.EXTRA_INCOMING_NUMBER); 
         Log.w("NUMBER",number); 
        } 
       } 
       Class c = null; 
       try { 
         c = Class.forName(telephonyManager.getClass().getName()); 
       } catch (ClassNotFoundException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
       } 
       Method m = null; 
       try { 
         m = c.getDeclaredMethod("getITelephony"); 
       } catch (SecurityException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
       } catch (NoSuchMethodException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
       } 
     m.setAccessible(true); 
     try { 
      telephonyService = (ITelephony)m.invoke(telephonyManager); 
     } catch (IllegalArgumentException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IllegalAccessException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (InvocationTargetException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     telephonyManager.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE); 
     }//onReceive() 

     class MyPhoneStateListener extends PhoneStateListener 
      { 
       public void onCallStateChanged(int state, String incomingNumber) 
       { 

        switch (state) 
        { 
         case TelephonyManager.CALL_STATE_RINGING: 
          if (true) // if incomingNumber need to be blocked 
          { 
           if(Enable_chkbox.isChecked()) 
           { 
           try { 
           end_call=telephonyService.endCall(); 
           if(end_call==true) 
           {       
            android.telephony.SmsManager sms = android.telephony.SmsManager.getDefault(); 
            sms.sendTextMessage(number, null, SMS, null, null); 
           } 
           Toast.makeText(getApplicationContext(),"Enabled", Toast.LENGTH_LONG).show(); 
           } catch (Exception e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
            }//try catch 
          }//if chkbox enabled 
          } 
          break; 
         default: 
          break; 
        } 
        } 
       } 

      };//Broadcast receiver 
      IntentFilter filter= new IntentFilter("android.intent.action.PHONE_STATE"); 
      registerReceiver(CallBlocker, filter); 

    } 

註銷在:

@Override 
protected void onDestroy() { 
    // TODO Auto-generated method stub 
    super.onDestroy(); 
    unregisterReceiver(CallBlocker); 
    this.finish(); 
     Toast.makeText(getApplicationContext(), "text", Toast.LENGTH_LONG).show(); 
     } 

一切工作正常,除非我按後退按鈕..

+0

你有註冊接收器,但我想你忘了取消註冊該接收器..請取消註冊該... –

+0

我已經註銷我的接收器.. – Deepthi

+1

@ user1362681 - 只是一個樣式點 - 在Java中,總是以小寫字母開始變量。大寫的名字通常保留給類型。 – derekerdmann

回答

0

是啊,你有一個資源你不發佈/取消註冊 需要更多代碼才能具體

+0

Metnik:謝謝你的迴應。我只注意到你的答案被某個人拒絕了。所以,無論如何,從我作爲一個相關的猜測upvote沒有幫助我。我已經用我的代碼更新了我的問題。請幫助:( – Deepthi

+0

我想我會做一些完全不同的事情在你的情況。 我不,也許這只是我,看看你爲什麼你的代碼做你的廣播公司 這是更安全,更容易,添加他們在xml中。哪個android也告訴你是最好的。 –

+0

非常感謝Anders Metnik ..我會嘗試一下然後.... – Deepthi

1

你沒有顯示你的代碼,所以這是一個猜測。

的線索是在這裏:

05-18 16:58:32.614:E/ActivityThread(3265):活動com.deepthi.blockmycalls.BlockMyCallsActivity已泄漏IntentReceiver [email protected]最初在這裏註冊。你是否錯過了對unregisterReceiver()的調用?

當您的活動完成後,您是否註銷您的接收器?

@Override 
protected void onPause(){ 

    super.onPause(); 

    if (myMessageReceiver != null){ 
     unregisterReceiver(myMessageReceiver); 
     myMessageReceiver = null; 
    } 
} 
+0

感謝您的回覆,但我已經註銷它 – Deepthi

+0

我已經更新了我的問題與我的代碼。請幫助 – Deepthi

+0

呵呵,爲什麼? – Simon

0

如果您可以發佈您的代碼,也許會更容易幫助您,但似乎您註冊了兩次接收器。

+0

感謝您的回覆。我只註冊了一次。我已經更新了我的問題和代碼.. – Deepthi

+0

@ user1362681我仍然想想你註冊兩次之前註銷。也許當你推回按鈕OnCheckedChange再次調用。嘗試放置一個斷點和調試應用程序。 – gutiory

+0

@gutiory增加了投票,因爲我認爲當有人進來並投票給我們,當我們試圖解釋而沒有看到代碼時,這是一種恥辱。也發生在我身上。 –

相關問題