Re: Android Service Tutorial - ServiceConnection leak

3,570 views
Skip to first unread message

Lars Vogel

unread,
Jun 12, 2013, 5:50:54 AM6/12/13
to vog...@googlegroups.com
Hi Alex,

thanks for the report. I adjusted the tutorial so that the lifecycle of the Activity is correctly considered.

Best regards, Lars


2012/8/20 Alex Little <al...@alexlittle.net>
Hi,

Thanks, for all the great tutorials, I've found them really useful.

I just have a comment/feedback about the Android Service Tutorial (http://www.vogella.com/articles/AndroidServices/article.html), specifically the code in section 8 (Define and consume your own service).

Although the code functions fine, when I close the application I get the following error in my logcat regarding ServiceConnection leak:

08-13 15:03:59.461: E/ActivityThread(355): Activity org.digitalcampus.testing.MainActivity has leaked ServiceConnection org.digitalcampus.testing.MainActivity$1@44f44458 that was originally bound here
08-13 15:03:59.461: E/ActivityThread(355): android.app.ServiceConnectionLeaked: Activity org.digitalcampus.testing.MainActivity has leaked ServiceConnection org.digitalcampus.testing.MainActivity$1@44f44458 that was originally bound here
08-13 15:03:59.461: E/ActivityThread(355):     at android.app.ActivityThread$PackageInfo$ServiceDispatcher.<init>(ActivityThread.java:1121)
08-13 15:03:59.461: E/ActivityThread(355):     at android.app.ActivityThread$PackageInfo.getServiceDispatcher(ActivityThread.java:1016)
08-13 15:03:59.461: E/ActivityThread(355):     at android.app.ContextImpl.bindService(ContextImpl.java:863)
08-13 15:03:59.461: E/ActivityThread(355):     at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
08-13 15:03:59.461: E/ActivityThread(355):     at org.digitalcampus.testing.MainActivity.doBindService(MainActivity.java:67)
08-13 15:03:59.461: E/ActivityThread(355):     at org.digitalcampus.testing.MainActivity.onCreate(MainActivity.java:39)
08-13 15:03:59.461: E/ActivityThread(355):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-13 15:03:59.461: E/ActivityThread(355):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-13 15:03:59.461: E/ActivityThread(355):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
...

However, I fixed this by adding the following to the MainActivity class:

public void onDestroy() {
    mConnection = null;
}

Not sure if there is another (better) way to handle this, but it seemed to work for me. For info I was running the code on Android 2.3.7 (Cyanogenmod),

Cheers,
Alex

--
You received this message because you are subscribed to the Google Groups "vogella" group.
To view this discussion on the web visit https://groups.google.com/d/msg/vogella/-/cGzaQkpjEsUJ.
To post to this group, send email to vog...@googlegroups.com.
To unsubscribe from this group, send email to vogella+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/vogella?hl=en.

Reply all
Reply to author
Forward
0 new messages