Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Android memory leak errors(unregistered reciever)  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LogCat:

05-17 19:07:22.804: E/ActivityThread(20104): Activity com.example.mytaskmanager.MyActionBar has leaked IntentReceiver com.example.mytaskmanager.Battery$1@417d1238 that was originally registered here. Are you missing a call to unregisterReceiver()?
05-17 19:07:22.804: E/ActivityThread(20104): android.app.IntentReceiverLeaked: Activity com.example.mytaskmanager.MyActionBar has leaked IntentReceiver com.example.mytaskmanager.Battery$1@417d1238 that was originally registered here. Are you missing a call to unregisterReceiver()?
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:781)
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1067)
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1054)
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1048)
05-17 19:07:22.804: E/ActivityThread(20104): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:341)
05-17 19:07:22.804: E/ActivityThread(20104): at com.example.mytaskmanager.Battery.onCreate(Battery.java:114)
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:801)
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1038)
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.BackStackRecord.run(BackStackRecord.java:622)
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1396)
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
05-17 19:07:22.804: E/ActivityThread(20104): at android.os.Handler.handleCallback(Handler.java:605)
05-17 19:07:22.804: E/ActivityThread(20104): at android.os.Handler.dispatchMessage(Handler.java:92)
05-17 19:07:22.804: E/ActivityThread(20104): at android.os.Looper.loop(Looper.java:154)
05-17 19:07:22.804: E/ActivityThread(20104): at android.app.ActivityThread.main(ActivityThread.java:4624)
05-17 19:07:22.804: E/ActivityThread(20104): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 19:07:22.804: E/ActivityThread(20104): at java.lang.reflect.Method.invoke(Method.java:511)
05-17 19:07:22.804: E/ActivityThread(20104): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
05-17 19:07:22.804: E/ActivityThread(20104): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
05-17 19:07:22.804: E/ActivityThread(20104): at dalvik.system.NativeStart.main(Native Method)


My app has action bar with 3 fragment tabs.
In the second fragment I have these errors and as I understand I have to unregister Reciever but I'm not sure where in the code to do that





I tried this but now I have receiver not registered errors, should I move the register code to onCreateView() and leave the unregister like this ?
(Is onDestroyView() still called when I select the Battery tab and then click the home button? because if not I suppose the errors wouldn't be solved )



 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should add the code for unregistering the broadcast receiver in the OnDestroy method of the activity.

Override the onDestroy method and place the unregisterReceiver(batteryInfoReceiver); in it and there you go...!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!