android


Android marshmallow WifiManager leaking IntentReceiver


Here's the scenario, I have a LoginActivity that makes use of the WifiManager to obtain the IP address like this:
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
String ipAddress = wifiManager.getConnectionInfo().getIpAddress();
I do not register any receiver to receive any WiFi updates. I use the WifiManager to obtain the IP Address only and nothing else.
Now when I complete login, I call finish() in LoginActivity and start SplashActivity and that's when I see the following log in console:
LoginActivity has leaked IntentReceiver android.net.wifi.WifiManager
that was originally registered here. Are you missing a call to
unregisterReceiver()?
And I get this log only on marshmallow. This does not happen on <6.0 devices ever. Also on marshmallow, the app never crashes but I see this log every time.
If anyone can explain this behaviour?
I had the same error, but only when running in debug for some reason.
Adding: getApplicationContext() fixed the issue for me. (Although I'm not entirely sure why?)
WifiManager wifi_manager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
After doing a bit more research it looks like when you transition from one activity to the other the context no longer exists.
getApplicationContext() - Returns the context for all activities running in application.
getContext() - Returns the context view only current running activity.
So it's probably best use getApplicationContext() for anything that should survive for the lifetime of your app.

Related Links

Finding the point on the progressbar where the surface was clicked
Android Autocomplete textview onitemclicklistener not working
Android Source: Repo not displaying any initialization message
adb does not see devices connected to Apple Thunderbolt Cinema Display
How to create TextView with reflection on android?
MediaRecorder issue - throws FileNotFoundException when I try to write to sdcard
how to sort arrays/list and return the result in android?
android imagebutton answers and imageview questions
use ActionBarSherlock as library in my own project
About Android Query library
Are These For Memory Leak Warnings
Only display tabs in action bar
TextView not displaying Characters like “à è ì ò ù” in android
Additional .mp4 decoders for VideoView
Way to reset Android HOME Screen Default?
Android 2d and 3d synchornization

Categories

HOME
xml
prism
spark-streaming
css3
alexa-skills-kit
requirements
xbee
maxscript
trac
minecraft-forge
octave
ibeacon-android
enthought
appcelerator-studio
startup
angular-dart
selenium-ide
shared-libraries
libusb
searchview
symfony-2.8
dimensional-modeling
googlebot
kendo-mobile
cgbitmapcontext
displaytag
fat
has-and-belongs-to-many
genexus-sd
sqsh
finagle
autodesk-designautomation
dotspatial
send
classcastexception
modalviewcontroller
browser-extension
batching
fiware-cygnus
imagenet
git-rewrite-history
loading
metawidget
naming
linqpad
movilizer
photos
httrack
libgphoto2
openrasta
wcftestclient
user-defined-fields
remedy
modelsim
java-6
dt
gameplay-kit
change-tracking
gets
cubism.js
beamer
redis-cluster
fuzzywuzzy
nupic
jbase
boomerang
toolkit
snoop
teamcity-9.1
primitive-types
browserify-shim
ss7
xml-dsig
alternate
draw2d-js
scrypt
oocss
beaker-testing
tlf
route-provider
pagedown
xcode3.2
zope.interface
josql
workflow-services
entitydatasource
pylucene
umra
mtu
load-time
globals
cuda.net
fail-fast-fail-early

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App