1
1
package com .firebase .ui .auth .util .signincontainer ;
2
2
3
+ import android .content .Intent ;
3
4
import android .os .Bundle ;
4
5
import android .support .annotation .NonNull ;
5
6
import android .support .annotation .Nullable ;
6
7
import android .text .TextUtils ;
7
8
import android .util .Log ;
9
+ import android .util .Pair ;
8
10
import android .widget .Toast ;
9
11
10
12
import com .firebase .ui .auth .ui .FragmentBase ;
@@ -32,7 +34,9 @@ public abstract class SmartLockBase<R extends Result> extends FragmentBase imple
32
34
private static final String TAG = "SmartLockBase" ;
33
35
34
36
protected GoogleApiClient mGoogleApiClient ;
37
+
35
38
private boolean mWasProgressDialogShowing ;
39
+ private Pair <Integer , Intent > mActivityResultPair ;
36
40
37
41
/**
38
42
* Translate a Firebase Auth provider ID (such as {@link GoogleAuthProvider#PROVIDER_ID}) to
@@ -110,7 +114,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
110
114
@ Override
111
115
public void onStart () {
112
116
super .onStart ();
113
- if (mWasProgressDialogShowing ) {
117
+ if (mActivityResultPair != null ) {
118
+ mHelper .finish (mActivityResultPair .first , mActivityResultPair .second );
119
+ } else if (mWasProgressDialogShowing ) {
114
120
mHelper .showLoadingDialog (com .firebase .ui .auth .R .string .progress_dialog_loading );
115
121
mWasProgressDialogShowing = false ;
116
122
}
@@ -135,6 +141,18 @@ public void cleanup() {
135
141
}
136
142
}
137
143
144
+ @ Override
145
+ public void finish (int resultCode , Intent resultIntent ) {
146
+ if (getActivity () == null ) {
147
+ // Because this fragment lives beyond the activity lifecycle, Fragment#getActivity()
148
+ // might return null and we'll throw a NPE. To get around this, we wait until the
149
+ // activity comes back to life in onStart and we finish it there.
150
+ mActivityResultPair = new Pair <>(resultCode , resultIntent );
151
+ } else {
152
+ super .finish (resultCode , resultIntent );
153
+ }
154
+ }
155
+
138
156
@ Override
139
157
public void onConnectionFailed (@ NonNull ConnectionResult connectionResult ) {
140
158
Toast .makeText (getContext (),
0 commit comments