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

Request to turn on the GPS is closing the app #370

Closed
jcabrerahi opened this issue May 27, 2020 · 11 comments
Closed

Request to turn on the GPS is closing the app #370

jcabrerahi opened this issue May 27, 2020 · 11 comments
Labels

Comments

@jcabrerahi
Copy link

When I request to enable service (activate the GPS), the app close, the GPS turn on but the app should be open again. ¿There is a method for don't have to reopen the app?

Tested on:

  • Android, API Level 26, simulator.
  • Android, API Level 28, real device.

I'm trying with the repo example.

@jcabrerahi
Copy link
Author

Im using Flutter channel beta, v1.17.0-3.3.pre

D/AndroidRuntime(10983): Shutting down VM
E/AndroidRuntime(10983): FATAL EXCEPTION: main
E/AndroidRuntime(10983): Process: com.lyokone.locationexample, PID: 10983
E/AndroidRuntime(10983): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=4097, result=-1, data=Intent { (has extras) }} to activity {com.lyokone.locationexample/io.flutter.embedding.android.FlutterActivity}: java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime(10983): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4324)
E/AndroidRuntime(10983): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:4367)
E/AndroidRuntime(10983): 	at android.app.ActivityThread.-wrap19(Unknown Source:0)
E/AndroidRuntime(10983): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649)
E/AndroidRuntime(10983): 	at android.os.Handler.dispatchMessage(Handler.java:105)
E/AndroidRuntime(10983): 	at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime(10983): 	at android.app.ActivityThread.main(ActivityThread.java:6541)
E/AndroidRuntime(10983): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(10983): 	at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
E/AndroidRuntime(10983): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
E/AndroidRuntime(10983): Caused by: java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime(10983): 	at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:139)
E/AndroidRuntime(10983): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:231)
E/AndroidRuntime(10983): 	at com.lyokone.location.FlutterLocation.onActivityResult(FlutterLocation.java:162)
E/AndroidRuntime(10983): 	at io.flutter.embedding.engine.FlutterEnginePluginRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEnginePluginRegistry.java:691)
E/AndroidRuntime(10983): 	at io.flutter.embedding.engine.FlutterEnginePluginRegistry.onActivityResult(FlutterEnginePluginRegistry.java:378)
E/AndroidRuntime(10983): 	at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:597)
E/AndroidRuntime(10983): 	at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:582)
E/AndroidRuntime(10983): 	at android.app.Activity.dispatchActivityResult(Activity.java:7235)
E/AndroidRuntime(10983): 

Flutter doctor

[√] Flutter (Channel beta, v1.17.0-3.3.pre, on Microsoft Windows [Version 10.0.16299.125], locale es-EC)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.5)
[√] VS Code (version 1.45.1)
[√] Connected device (3 available)

@fried19
Copy link

fried19 commented Jun 11, 2020

I have the same issue

@jcabrerahi
Copy link
Author

Check if your code is running twice! In my case, the pettition for enable GPS was running twice, so the app crash. It solve the issue for me.

@fried19
Copy link

fried19 commented Jun 15, 2020

Still having the same problem.I already checked my code but nothing run twice.

@MaheshPeri19
Copy link

MaheshPeri19 commented Jun 25, 2020

I had the same issue when i request permission for user device location first and then for request for gps. At this time, it is calling two times and app is crashed with retry already submitted.

I solved it like this :
So that i have requested first for gps i.e location.requestService() and then location.requestPermission().

Note : not sure it is calling two times, but when i click first time on "No thanks button", it is not dismissing, then if i click again, app is crashing.

@rebaz94
Copy link

rebaz94 commented Jun 25, 2020

I have same issue and app crashed with retry already submitted.
I solved by changing onActivityResult in FlutterLocation.java.

Change to this it will clear result object and prevent calling multiple times

@Override
    public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
        if (result == null) {
            return false;
        }
        switch (requestCode) {
            case GPS_ENABLE_REQUEST:
                if (resultCode == Activity.RESULT_OK) {
                    result.success(1);
                } else {
                    result.success(0);
                }
                clearResultObj();
                break;
            case REQUEST_CHECK_SETTINGS:
                if (resultCode == Activity.RESULT_OK) {
                    startRequestingLocation();
                    clearResultObj();
                    return true;
                }

                result.error("SERVICE_STATUS_DISABLED", "Failed to get location. Location services disabled", null);
                clearResultObj();
                return false;
            default:
                clearResultObj();
                return false;
        }
    }

    private void clearResultObj(){
        result = null;
    }

@fried19
Copy link

fried19 commented Jun 25, 2020

Thank you all. I finally created a global variable to which I affect true as soon as I came out of the onActivityResult method as @rebaz94 did. And it works properly.

@stale
Copy link

stale bot commented Jul 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the inactive label Jul 25, 2020
@stale stale bot closed this as completed Aug 1, 2020
@wisnuwiry
Copy link

wisnuwiry commented Oct 16, 2020

I have the same issue in the latest version: 3.0.2 & Flutter: 1.20

Please help me @Lyokone

@sanjaymajoka
Copy link

Hi I am facing issue in 3.2.4

@shahpasandar
Copy link

I am facing issue in 4.4.0

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

No branches or pull requests

7 participants