Autore Topic: Errore Leaked intentReceiver  (Letto 1030 volte)

Offline psicomant

  • Utente junior
  • **
  • Post: 95
  • Respect: 0
    • Mostra profilo
  • Sistema operativo:
    OSX 10.6.5
Errore Leaked intentReceiver
« il: 17 Gennaio 2011, 12:18:32 CET »
0
Salve, ho riscontrato un errore di leaked intentReceiver di questo tipo:
Codice: [Seleziona]
01-17 12:00:35.789: ERROR/ActivityThread(16131): Service cloudsensor.csams.Boot.BootNew has leaked IntentReceiver cloudsensor.csams.Boot.BootNew$1@43d6fbd0 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-17 12:00:35.789: ERROR/ActivityThread(16131): android.app.IntentReceiverLeaked: Service cloudsensor.csams.Boot.BootNew has leaked IntentReceiver cloudsensor.csams.Boot.BootNew$1@43d6fbd0 that was originally registered here. Are you missing a call to unregisterReceiver()?
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:797)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:608)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.app.ApplicationContext.registerReceiverInternal(ApplicationContext.java:724)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:711)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:705)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:308)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at cloudsensor.csams.Boot.BootNew.registerReceiver(BootNew.java:99)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at cloudsensor.csams.Boot.BootNew.onCreate(BootNew.java:68)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2780)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.app.ActivityThread.access$3200(ActivityThread.java:119)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1917)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.os.Looper.loop(Looper.java:123)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at android.app.ActivityThread.main(ActivityThread.java:4363)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at java.lang.reflect.Method.invokeNative(Native Method)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at java.lang.reflect.Method.invoke(Method.java:521)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-17 12:00:35.789: ERROR/ActivityThread(16131):     at dalvik.system.NativeStart.main(Native Method)

Si tratta di un Service in cui per la registrazione del broadcastIntent faccio:
Codice (Java): [Seleziona]
private void registerReceiver() {
        IntentFilter filter = new IntentFilter("ACTION_FE_BOOTED");
        /*
         * a broadcast receiver to manage action arrived from Feasibility Engine
         */

        //private class BootBroadcastReceiver extends BroadcastReceiver {
        bbr = new  BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
               
                // send an action to StartStop interface
                Intent UIintent = new Intent("STOP_NOTIFICATION_NORMAL");
                sendBroadcast(UIintent);
            }    
        };
        registerReceiver(bbr, filter);
        }

e per la deregistrazione
Codice (Java): [Seleziona]
private void unregisterReceiver(){
                // unregister all previous registered BroadcastReceivers
                try{
                        BootNew.this.getApplicationContext().unregisterReceiver(bbr);
                }catch(IllegalArgumentException e){
                        Log.e("Illegal Argument", "Receiver not registered!");
                }
        }

che chiamo nella

Codice (Java): [Seleziona]
@Override
        public void onDestroy() {
                unregisterReceiver();
                super.onDestroy();
        }

Qaulcuno ha qualche idea?

Offline bradipao

  • Moderatore globale
  • Utente storico
  • *****
  • Post: 4043
  • keep it simple
  • Respect: +567
    • Github
    • Google+
    • bradipao
    • Mostra profilo
  • Dispositivo Android:
    Nexus 5
  • Play Store ID:
    Bradipao
  • Sistema operativo:
    W7
Re:Errore Leaked intentReceiver
« Risposta #1 il: 17 Gennaio 2011, 12:33:33 CET »
0
Sicuro di non registrare due volte il receiver (sia in OnCreate che in OnResume/OnStart )?

E/o di non fare unregistering nel corrispondente OnPause/OnStop ?
NON rispondo a domande nei messaggi privati
Bradipao @ Play Store

Offline Ricky`

  • Amministratore
  • Utente storico
  • *****
  • Post: 3489
  • Respect: +507
    • Github
    • Google+
    • rciovati
    • Mostra profilo
Re:Errore Leaked intentReceiver
« Risposta #2 il: 17 Gennaio 2011, 12:51:11 CET »
0
Io fossi in te proverei a fare questa prova:

cambia il codice di receiverReceiver:
Codice (Java): [Seleziona]
private static final BroadcastReceiver bbr = new  BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
               
                // send an action to StartStop interface
                Intent UIintent = new Intent("STOP_NOTIFICATION_NORMAL");
                sendBroadcast(UIintent);
            }    
        };

private void registerReceiver() {
        IntentFilter filter = new IntentFilter("ACTION_FE_BOOTED");
        registerReceiver(bbr, filter);
}

e
Codice (Java): [Seleziona]
private void unregisterReceiver(){
                // unregister all previous registered BroadcastReceivers
                try{
                        unregisterReceiver(bbr);
                }catch(IllegalArgumentException e){
                        Log.e("Illegal Argument", "Receiver not registered!");
                }
        }