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

Showing big view notifications with Firebase Cloud Messaging
Not able to upload an Image in Firebase Storage
Error with installing app on android device by AndroidStudio
How to make several mobile devices (both iOS and Android) communicate without using internet
OnClickListener doesn't change view in Custom BaseAdapter
Android studio palette is missing
How to parse inner JSON object using Gson in Android
Sending POST within BroadcastReceiver
In Exoplayer,How to reload and resume playback automatically?
Draw route using points slowly
cropped image and save it into mysqldatabse
The right way to implement twitter authentication
ConstraintLayout messes up after I change the src of an ImageView
QML Mouse area doesn't get unpressed while touching in Android
Error trying to import firebase-ui
Meteor signed release apk can't connect to server

Categories

HOME
paraview
fuelux
polymer
apache-flink
obfuscation
jwplayer
oracle-apex-5
knitr
grafana
x264
opengl-3
boto3
qpython
x-cart
jsonpath
intercom
symmetricds
http-post
event-sourcing
microsoft-dynamics-nav
mathprog
google-content-api
google-data-studio
oledb
microsoft-ocr
dpdk
pagespeed
windows-server-2003
wcag
bringtofront
carrierwave
volatile
login-script
activexobject
openwhisk
roblox
bc
health-monitoring
apache-stanbol
laravel-elixir
portforwarding
microsoft-metro
congestion-control
wc
x++
vaadin-elements
flask-restful
getchar
robomongo
page-replacement
template-toolkit
swingworker
taocp
pytables
wso2developerstudio
synonym
hclust
observablecollection
ikiwiki
uiactionsheet
nupic
exim4
directdraw
terracotta
avisynth
pax-exam
slash
atoi
skspritenode
keyup
rrule
dot.js
android-vibration
sql-scripts
nsmenu
raygun
live555
ray
square-bracket
syndicationfeed
xmltodict
ecslidingviewcontroller
bin
embedded-fonts
mongohq
diem
onload-event
server-administration
cascadingdropdown
chart-director
asplinkbutton
qtconcurrent
boost-msm
subgraph
database-create
predicatebuilder
virtualpathprovider
box2d-iphone
gobject-introspection
role
cdonts
socketserver
luajava
timertask
object-database
opml
tabpanel
build-environment
visualj#
todos
linfu-dynamicproxy
pnrp

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