88import io .flutter .embedding .engine .plugins .activity .ActivityPluginBinding ;
99import io .flutter .plugin .common .BinaryMessenger ;
1010import io .flutter .plugin .common .MethodChannel ;
11- import io .flutter .plugin .common .PluginRegistry .ViewDestroyListener ;
12- import io .flutter .view .FlutterNativeView ;
1311
1412/**
1513 * GoogleApiAvailabilityPlugin
@@ -25,29 +23,37 @@ public GoogleApiAvailabilityPlugin() {
2523 }
2624
2725 @ Override
28- public void onAttachedToActivity (ActivityPluginBinding binding ) {
29- methodCallHandler .setActivity (binding .getActivity ());
30- }
26+ public void onAttachedToActivity (ActivityPluginBinding binding ) {
27+ if (methodCallHandler != null ) {
28+ methodCallHandler .setActivity (binding .getActivity ());
29+ }
30+ }
3131
32- @ Override
33- public void onDetachedFromActivity () {
34- methodCallHandler .setActivity (null );
35- }
32+ @ Override
33+ public void onDetachedFromActivity () {
34+ if (methodCallHandler != null ) {
35+ methodCallHandler .setActivity (null );
36+ }
37+ }
3638
37- @ Override
38- public void onReattachedToActivityForConfigChanges (@ NonNull ActivityPluginBinding binding ) {
39- methodCallHandler .setActivity (binding .getActivity ());
40- }
39+ @ Override
40+ public void onReattachedToActivityForConfigChanges (@ NonNull ActivityPluginBinding binding ) {
41+ if (methodCallHandler != null ) {
42+ methodCallHandler .setActivity (binding .getActivity ());
43+ }
44+ }
4145
42- @ Override
43- public void onDetachedFromActivityForConfigChanges () {
44- methodCallHandler .setActivity (null );
45- }
46+ @ Override
47+ public void onDetachedFromActivityForConfigChanges () {
48+ if (methodCallHandler != null ) {
49+ methodCallHandler .setActivity (null );
50+ }
51+ }
4652
47- @ Override
48- public void onAttachedToEngine (FlutterPluginBinding binding ) {
49- registerPlugin (binding .getApplicationContext (), binding .getBinaryMessenger ());
50- }
53+ @ Override
54+ public void onAttachedToEngine (@ NonNull FlutterPluginBinding binding ) {
55+ registerPlugin (binding .getApplicationContext (), binding .getBinaryMessenger ());
56+ }
5157
5258 @ Override
5359 public void onDetachedFromEngine (@ NonNull FlutterPluginBinding binding ) {
@@ -61,7 +67,9 @@ private void registerPlugin(Context context, BinaryMessenger messenger) {
6167 }
6268
6369 private void unregisterPlugin () {
64- channel .setMethodCallHandler (null );
65- channel = null ;
70+ if (channel != null ) {
71+ channel .setMethodCallHandler (null );
72+ channel = null ;
73+ }
6674 }
6775}
0 commit comments