簡體   English   中英

誰能告訴我為什么我在logcat中收到此錯誤?

[英]Can anyone tell me why do I get this error in logcat?

我是Android的新手,請告訴我以下log cat錯誤是什么意思,如何消除它? 在我的應用程序中,我正在阻止不必要的呼叫。當我在使用我的應用程序時按下后退按鈕時,出現此錯誤。 請幫忙

05-18 16:58:32.614: E/ActivityThread(3265): Activity com.deepthi.blockmycalls.BlockMyCallsActivity has leaked IntentReceiver com.deepthi.blockmycalls.BlockMyCallsActivity$1@44f03d18 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 com.deepthi.blockmycalls.BlockMyCallsActivity$1@44f03d18 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 com.deepthi.blockmycalls.BlockMyCallsActivity$1@44efa3a8 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 com.deepthi.blockmycalls.BlockMyCallsActivity$1@44efa3a8 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();
        }

除非我按返回按鈕,否則一切都正常。

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

線索在這里:

05-18 16:58:32.614:E / ActivityThread(3265):活動com.deepthi.blockmycalls.BlockMyCallsActivity泄漏了最初在此處注冊的IntentReceiver com.deepthi.blockmycalls.BlockMyCallsActivity$1@44efa3a8。 您是否缺少對unregisterReceiver()的調用?

活動結束后,您要注銷接收器嗎?

@Override
protected void onPause(){

    super.onPause();

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

是的,您擁有不釋放/取消注冊的資源,需要更多代碼才能具體說明

如果您可以發布代碼,也許會更容易為您提供幫助,但似乎您正在兩次注冊接收者。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM