8
8
import io .flutter .embedding .engine .plugins .activity .ActivityPluginBinding ;
9
9
import io .flutter .plugin .common .BinaryMessenger ;
10
10
import io .flutter .plugin .common .MethodChannel ;
11
- import io .flutter .plugin .common .PluginRegistry .ViewDestroyListener ;
12
- import io .flutter .view .FlutterNativeView ;
13
11
14
12
/**
15
13
* GoogleApiAvailabilityPlugin
@@ -25,29 +23,37 @@ public GoogleApiAvailabilityPlugin() {
25
23
}
26
24
27
25
@ 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
+ }
31
31
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
+ }
36
38
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
+ }
41
45
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
+ }
46
52
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
+ }
51
57
52
58
@ Override
53
59
public void onDetachedFromEngine (@ NonNull FlutterPluginBinding binding ) {
@@ -61,7 +67,9 @@ private void registerPlugin(Context context, BinaryMessenger messenger) {
61
67
}
62
68
63
69
private void unregisterPlugin () {
64
- channel .setMethodCallHandler (null );
65
- channel = null ;
70
+ if (channel != null ) {
71
+ channel .setMethodCallHandler (null );
72
+ channel = null ;
73
+ }
66
74
}
67
75
}
0 commit comments