2015-05-16 4 views
6

ottengo il seguente erroreTi manca una chiamata per annullare la registrazioneReceiver()? in Android

"Vi manca una chiamata per annullare la registrazione del ricevitore"

android.app.IntentReceiverLeaked: Activity com.apps.activities.MainActivity has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()? 
       at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:809) 


at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:610) 
      at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1478) 
      at android.app.ContextImpl.registerReceiver(ContextImpl.java:1458) 
      at android.app.ContextImpl.registerReceiver(ContextImpl.java:1452) 
      at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:467) 

mio codice è

private BroadcastReceiver actionConversation = new BroadcastReceiver() 
{ 

    @Override 
    public void onReceive(Context context, Intent intent) { 
      setAdapter(); 
    } 
}; 

private void registerBroadCasts() { 
    IntentFilter intentConnection = new IntentFilter(
      Constants.CONVERSATION_SCREEN); 
    getActivity().registerReceiver(actionConversation, intentConnection); 
} 

e chiamo registerBroadCasts() nel metodo onCreate.

+0

inserisci il tuo codice per favore –

+0

@Kinjal se stai lavorando con 'BroadcastReceiver' devi' annullare la registrazione di quel ricevitore nel metodo OnDestroy() 'di Attività. –

+0

@Kinjal: Felice di aiutare .. :) –

risposta

9

immagino che si sta utilizzando GCM nel vostro application.In l'attività in cui si sta registrando un dispositivo per GCM, scrivere il codice seguente:

@Override 
    public void onDestroy() { 
     // TODO Auto-generated method stub 

     try{ 
      if(mHandleMessageReceiver!=null) 
       unregisterReceiver(mHandleMessageReceiver); 
     }catch(Exception e) 
     { 

     } 
     super.onDestroy(); 

    } 

dove mHandleMessageReceiver è l'istanza del BroadcastReceiver .

+0

grazie per la tua risposta – Kinjal

+0

@ kgandroid ... Hai salvato il mio tempo .. + 1 voto per il tuo ans.Grazie –

+0

Cheers ... !!!!!! – kgandroid