On Wed, Jun 29, 2011 at 6:02 AM, <dep> <[email protected]> wrote: > I’m developing an application with uses AsyncTask. In the > doInBackground() method I register a BroadcastReceiver and when the > task is finished I unregister it. > > The problem appears when the screen orientation changes in the middle > of the execution, as the task is not finished the BroadcastReceiver is > not ungistered and, therefore, I get this exception (after registering > again the BroadcastReceiver): > > android.app.IntentReceiverLeaked: Activity myActivity has leaked > IntentReceiver myActivity $WifiReceiver@40530508 that was originally > registered here. Are you missing a call to unregisterReceiver()? > > Do you know any way to be aware of this change and unregister the > BroadcastReceiver before the new AsyncTask is executed on onResume ()?
Your AsyncTask is not registering the BroadcastReceiver, as there is no registerReceiver() method on AsyncTask. Rather, some Context is registering the BroadcastReceiver. Given your error, presumably it is an Activity, with your AsyncTask as a non-static inner class. You really need to change that AsyncTask to be a static inner class or a standalone Java class, as otherwise you will have all sorts of challenges when it comes to orientation changes and other configuration changes. Along the way, that will help make it more explicit that the Activity is the one who is registering the BroadcastReceiver, and that the receiver's events will be delivered on the main application thread. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training in Oslo: http://bit.ly/fjBo24 -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

