Thanks Mark, I no sure about the difference between registering the event on the activity or registering it on the application context, can ´t I pass the broadcastReceiver object thought onRetainNonConfigurationInstance() if I made it on the activity?
Another problem would be what happends if I have another listener (i.e. GPS location update listenes) in the same activity, with this solution is not posible to pass 2 different objects(listeners) to the onRetainNonConfigurationInstance, any solution? Thank you so much. On 15 jul, 00:14, Mark Murphy <[email protected]> wrote: > Rather than calling registerReceiver() on the Activity, call it on the > Application context via getApplicationContext().registerReceiver(). > Then, pass the receiver object via onRetainNonConfigurationInstance(), > so you unregister the same receiver when you are done. > > > > On Thu, Jul 14, 2011 at 7:27 AM, <Hera> <[email protected]> wrote: > > Hello, > > > I’m having problems with BroadcastReceivers when the screen > > orientation changes. > > My Activity registers for receiving WiFi scans with a > > BroadcastReceiver and when the scan is done: (1) > > unregisterReceiver(mWifiReceiver), (2) I made some things with the > > results (by using an AsynkTask thread) and finally, when the thread is > > finished (3) the activity starts another WiFi scan and the whole > > process starts again. > > > Everything works fine until a screen orientation changes occurs: > > > If I do not unregisterReceiver() on the > > onRetainNonConfigurationInstance method I get this exception > > > Activity myActivity has leaked IntentReceiver myActivity > > $WifiReceiver@405efad0 that was originally registered here. Are you > > missing a call to unregisterReceiver()? > > > While if I unregisterReceiver(), I get this one: > > > ERROR/AndroidRuntime(1490): java.lang.RuntimeException: Error > > receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS } in > > myActivity $WifiReceiver@406b4668 > > > Could someone tell me the correct way to manage BroadcastReceiver in > > screen orientation changes? > > > -- > > 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 > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy > > Android App Developer Books:http://commonsware.com/books -- 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

