Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MainActivity has leaked ServiceConnection when press Back exit Wear app #10

Open
huytower opened this issue Jun 18, 2021 · 3 comments
Open

Comments

@huytower
Copy link

huytower commented Jun 18, 2021

Hello,

I got the exception as title in above, since I :

  • created new project
  • apply library in pubspec.yaml file
  • create Container widget (empty widget)
  • run project
  • application open as usual
  • press Exit
  • the exception in below, has appeared

Please help me check to avoid this exception,
Thanks,

p/s : I did not add anything in Manifest.xml file and build.gradle file (in folder /android)

EXCEPTION

E/ActivityThread( 3770): Activity flutter.wear.MainActivity has leaked ServiceConnection com.google.android.wearable.compat.WearableActivityController$AmbientServiceConnection@efc6b0a that was originally bound here
E/ActivityThread( 3770): android.app.ServiceConnectionLeaked: Activity flutter.wear.MainActivity has leaked ServiceConnection com.google.android.wearable.compat.WearableActivityController$AmbientServiceConnection@efc6b0a that was originally bound here
E/ActivityThread( 3770): at android.app.LoadedApk$ServiceDispatcher.(LoadedApk.java:1336)
E/ActivityThread( 3770): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1231)
E/ActivityThread( 3770): at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1450)
E/ActivityThread( 3770): at android.app.ContextImpl.bindService(ContextImpl.java:1422)
E/ActivityThread( 3770): at android.content.ContextWrapper.bindService(ContextWrapper.java:636)
E/ActivityThread( 3770): at com.google.android.wearable.compat.WearableActivityController.onCreate(WearableActivityController.java:134)
E/ActivityThread( 3770): at com.mjohnsullivan.flutterwear.wear.WearPlugin.onCreate(WearPlugin.kt:117)
E/ActivityThread( 3770): at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread( 3770): at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:216)
E/ActivityThread( 3770): at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:194)
E/ActivityThread( 3770): at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:185)
E/ActivityThread( 3770): at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:37)
E/ActivityThread( 3770): at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361)
E/ActivityThread( 3770): at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:300)
E/ActivityThread( 3770): at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339)
E/ActivityThread( 3770): at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
E/ActivityThread( 3770): at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131)
E/ActivityThread( 3770): at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:412)
E/ActivityThread( 3770): at android.app.Activity.performCreate(Activity.java:6682)
E/ActivityThread( 3770): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
E/ActivityThread( 3770): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
E/ActivityThread( 3770): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
E/ActivityThread( 3770): at android.app.ActivityThread.-wrap12(ActivityThread.java)
E/ActivityThread( 3770): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
E/ActivityThread( 3770): at android.os.Handler.dispatchMessage(Handler.java:102)
E/ActivityThread( 3770): at android.os.Looper.loop(Looper.java:154)
E/ActivityThread( 3770): at android.app.ActivityThread.main(ActivityThread.java:6119)
E/ActivityThread( 3770): at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread( 3770): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
E/ActivityThread( 3770): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

CODE

`HomePage.dart`

`class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return WatchShape(
      builder: (context, shape, child) {
        return AmbientMode(
          builder: (context, mode, child) {
            print('mode = $mode');

            return mode == WearMode.active ? ActiveWatchFace() : AmbientWatchFace();
          },
        );
      },
    );
  }

}`

`main.dart`

`void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    Widget home = Scaffold(
      body: Scaffold(
        body: Builder(
          builder: (context) => MainPage(),
        ),
      ),
    );

    return GetMaterialApp(
      debugShowCheckedModeBanner: true,
      home: home,
    );
  }
}

class MainPage extends StatefulWidget {
  @override
  MainPageState createState() => MainPageState();
}

class MainPageState extends State<MainPage> {
  @override
  Widget build(BuildContext context) => HomePage();
}`

TOOLS

[✓] Flutter (Channel master, 2.3.0-17.0.pre.228, on macOS 11.4 20F71 darwin-x64,
locale en-VN)
• Flutter version 2.3.0-17.0.pre.228 at /Users/huytd/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 49733a4850 (11 days ago), 2021-06-07 05:19:03 -0400
• Engine revision 2ffc823063
• Dart version 2.14.0 (build 2.14.0-186.0.dev)

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
✗ cmdline-tools component is missing
Run path/to/sdkmanager --install "cmdline-tools;latest"
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run flutter doctor --android-licenses to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for
more details.

[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5, Build version 12E262
• CocoaPods version 1.10.1

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] Android Studio
• Android Studio at /Users/huytd/Downloads/Android Studio
Preview.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[✓] Connected device (2 available)
• sdk google aw x86 (mobile) • emulator-5554 • android-x86 • Android
7.1.1 (API 25) (emulator)
• Chrome (web) • chrome • web-javascript • Google
Chrome 91.0.4472.106

! Doctor found issues in 1 category.

@huytower huytower changed the title java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener exception when press Back exit Wear app MainActivity has leaked ServiceConnection when press Back exit Wear app Jun 21, 2021
@Harishwarrior
Copy link

Happens to me also.

I/Choreographer( 5736): Skipped 33 frames!  The application may be doing too much work on its main thread.
D/QueuedWork( 5736): waited: [<1: 0, <2: 0, <4: 0, <8: 0, <16: 0, <32: 0, <64: 0, <128: 0, <256: 0, <512: 0, <1024: 1, <2048: 0, <4096: 0, <8192: 0, <16384: 0, >=16384: 0]
I/Choreographer( 5736): Skipped 165 frames!  The application may be doing too much work on its main thread.
E/ActivityThread( 5736): Activity com.kaust.teamtech.MainActivity has leaked ServiceConnection com.google.android.wearable.compat.WearableActivityController$AmbientServiceConnection@fddac4b that was originally bound here
E/ActivityThread( 5736): android.app.ServiceConnectionLeaked: Activity com.kaust.teamtech.MainActivity has leaked ServiceConnection com.google.android.wearable.compat.WearableActivityController$AmbientServiceConnection@fddac4b that was originally bound here
E/ActivityThread( 5736): 	at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1610)
E/ActivityThread( 5736): 	at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1502)
E/ActivityThread( 5736): 	at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1659)
E/ActivityThread( 5736): 	at android.app.ContextImpl.bindService(ContextImpl.java:1612)
E/ActivityThread( 5736): 	at android.content.ContextWrapper.bindService(ContextWrapper.java:698)
E/ActivityThread( 5736): 	at com.google.android.wearable.compat.WearableActivityController.onCreate(WearableActivityController.java:168)
E/ActivityThread( 5736): 	at com.mjohnsullivan.flutterwear.wear.WearPlugin.onCreate(WearPlugin.kt:117)
E/ActivityThread( 5736): 	at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread( 5736): 	at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:216)
E/ActivityThread( 5736): 	at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:194)
E/ActivityThread( 5736): 	at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:185)
E/ActivityThread( 5736): 	at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:37)
E/ActivityThread( 5736): 	at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361)
E/ActivityThread( 5736): 	at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:300)
E/ActivityThread( 5736): 	at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339)
E/ActivityThread( 5736): 	at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
E/ActivityThread( 5736): 	at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131)
E/ActivityThread( 5736): 	at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:501)
E/ActivityThread( 5736): 	at android.app.Activity.performCreate(Activity.java:7144)
E/ActivityThread( 5736): 	at android.app.Activity.performCreate(Activity.java:7135)
E/ActivityThread( 5736): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
E/ActivityThread( 5736): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2894)
E/ActivityThread( 5736): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3049)
E/ActivityThread( 5736): 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
E/ActivityThread( 5736): 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
E/ActivityThread( 5736): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
E/ActivityThread( 5736): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1809)
E/ActivityThread( 5736): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/ActivityThread( 5736): 	at android.os.Looper.loop(Looper.java:193)
E/ActivityThread( 5736): 	at android.app.ActivityThread.main(ActivityThread.java:6680)
E/ActivityThread( 5736): 	at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread( 5736): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/ActivityThread( 5736): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

@peelle
Copy link

peelle commented Oct 28, 2023

This is still happening in 2023. Any updates?

E/ActivityThread(12208): Activity .MainActivity has leaked ServiceConnection com.google.android.wearable.compat.WearableActivityController$AmbientServiceConnection@57f55bd that was originally bound here
E/ActivityThread(12208): android.app.ServiceConnectionLeaked: Activity .MainActivity has leaked ServiceConnection com.google.android.wearable.compat.WearableActivityController$AmbientServiceConnection@57f55bd that was originally bound here
E/ActivityThread(12208): at android.app.LoadedApk$ServiceDispatcher.(LoadedApk.java:1816)
E/ActivityThread(12208): at android.app.LoadedApk.getServiceDispatcherCommon(LoadedApk.java:1688)
E/ActivityThread(12208): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1667)
E/ActivityThread(12208): at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1819)
E/ActivityThread(12208): at android.app.ContextImpl.bindService(ContextImpl.java:1749)
E/ActivityThread(12208): at android.content.ContextWrapper.bindService(ContextWrapper.java:756)
E/ActivityThread(12208): at com.google.android.wearable.compat.WearableActivityController.onCreate(WearableActivityController.java:171)
E/ActivityThread(12208): at com.mjohnsullivan.flutterwear.wear.WearPlugin.onCreate(WearPlugin.kt:117)
E/ActivityThread(12208): at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread(12208): at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:216)
E/ActivityThread(12208): at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:194)
E/ActivityThread(12208): at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:185)
E/ActivityThread(12208): at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:37)
E/ActivityThread(12208): at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361)
E/ActivityThread(12208): at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:300)
E/ActivityThread(12208): at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339)
E/ActivityThread(12208): at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
E/ActivityThread(12208): at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131)
E/ActivityThread(12208): at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:646)
E/ActivityThread(12208): at android.app.Activity.performCreate(Activity.java:7998)
E/ActivityThread(12208): at android.app.Activity.performCreate(Activity.java:7978)
E/ActivityThread(12208): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
E/ActivityThread(12208): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3431)
E/ActivityThread(12208): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3610)
E/ActivityThread(12208): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
E/ActivityThread(12208): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/ActivityThread(12208): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/ActivityThread(12208): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2075)
E/ActivityThread(12208): at android.os.Handler.dispatchMessage(Handler.java:106)
E/ActivityThread(12208): at android.os.Looper.loop(Looper.java:223)
E/ActivityThread(12208): at android.app.ActivityThread.main(ActivityThread.java:7660)
E/ActivityThread(12208): at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread(12208): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/ActivityThread(12208): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

@Rexios80
Copy link

I released the wear_plus plugin which contains many updates. Please create an issue there if this issue persists after switching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants