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

!!! Android error on start: called start() while already started #539

Closed
Shakle opened this issue Mar 14, 2023 · 14 comments
Closed

!!! Android error on start: called start() while already started #539

Shakle opened this issue Mar 14, 2023 · 14 comments
Labels
android Platform android bug Something isn't working

Comments

@Shakle
Copy link

Shakle commented Mar 14, 2023

After some update recently - wether it was Android 13 QPR 2 (March Pixel update) or Flutter 3.7.7 on first camera initialization I get this error. In Example app it also happens. Did not check on other devices. I also guess that something related to it causes a crash from time to time when disabling/enabling camera.

ℹ️ Environment:

  • Pixel 7 Pro. Android 13 march 2023

✅ Steps to reproduce:

  1. Grant permissions to camera
  2. Freshly open an app
  3. Open camera screen

💡 Actual result:

  • mobile_scanner: MobileScannerException: code genericError, message: Called start() while already started

👍 Expected result:

  • no error
@tsomone
Copy link

tsomone commented Mar 15, 2023

You can do the trick by reloading camera with this code,

errorBuilder: (context, error, child) {
controller.stop();
controller.start();
return ScannerReloadingWidget(error: error);
}

its not recommended, but its working in my case

@teolemon teolemon added the android Platform android label Mar 20, 2023
@juliansteenbakker juliansteenbakker added the bug Something isn't working label Mar 21, 2023
@BryceCYB
Copy link

Add controller.stop(); in initState works for me.

  void initState() {
     // To fix on start error
    controller.stop();
    super.initState();
  }

@sebatorresi
Copy link

sebatorresi commented Apr 21, 2023

In my case I did

void initState() { cameraController.stop(); super.initState(); }

@Ishchik
Copy link

Ishchik commented May 4, 2023

It also reproduces when hitting Hot Restart on the screen with MobileScanner and navigating back to it

@arnabonetraker
Copy link

arnabonetraker commented May 29, 2023

@juliansteenbakker MobileScannerException: code genericError, message: Called start() while already started.
mobile_scanner: ^3.2.0 on flutter: 3.7.12.

@maulikchak
Copy link

same issue

@tologonkudaiberdiuulu
Copy link

Any progress @juliansteenbakker ?

@Logaritma26
Copy link

same

@JoshPark1
Copy link

We are seeing the same issue on iOS. Adding controller.stop() to initState does not resolve the issue.

@sanriodev
Copy link

We are seeing the same issue on iOS. Adding controller.stop() to initState does not resolve the issue.

Have you tried this?

#589 (comment)

While I definitelly think instantiating a new controller everytime isn't the prettiest I ended up using the same workaround as the user who wrote the comment.

Works fine for me. Maybe this can help?

I am still hoping this is getting fixed anytime soon though.

@navaronbracke
Copy link
Collaborator

This should no longer occur with the new beta, version 5.0.0-beta.1 , as the lifecycle is now no longer managed by mobile_scanner itself, due to issues with widget tree reparenting.

@cbassols
Copy link

cbassols commented Apr 9, 2024

This should no longer occur with the new beta, version 5.0.0-beta.1 , as the lifecycle is now no longer managed by mobile_scanner itself, due to issues with widget tree reparenting.

I've been fighting with this issue for the last two hours in the version 5.0.0-beta.2.
If I make a hot restart, I get "MobileScannerException: code genericError, message: Called start() while already started!"
The only way I have to make it work is completely closing the App and reopening it.

@navaronbracke
Copy link
Collaborator

navaronbracke commented Apr 10, 2024

I am aware that we should handle hot reload better, we have a tracking issue for that specifically:
#773

I still need to figure out if we can intercept it internally, or provide users with guidance around the use of reassemble().

@Quelich
Copy link

Quelich commented Jul 24, 2024

In my case, users were navigated to a new page that includes the scanner but when i do this back-and-forth navigation multiple times i was getting this error in debug console:
W/WindowOnBackDispatcher(11079): OnBackInvokedCallback is not enabled for the application. W/WindowOnBackDispatcher(11079): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest. with generic error called start() while already started

so i have updated AndroidManifest.xml in android/app/src/main by adding this line android:enableOnBackInvokedCallback="true" and it works.

For example:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your.package.name">

    <application
        android:label="Your App Name"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:enableOnBackInvokedCallback="true">
        <!-- ... other application configurations ... -->
    </application>

</manifest>

However, this change only works for targeting Android 13 (API level 33) and above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Platform android bug Something isn't working
Projects
None yet
Development

No branches or pull requests