File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
library/java/net/openid/appauth Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 21
21
import android .app .PendingIntent ;
22
22
import android .content .ActivityNotFoundException ;
23
23
import android .content .Context ;
24
+ import android .content .ContextWrapper ;
24
25
import android .content .Intent ;
25
26
import android .net .Uri ;
26
27
import android .os .AsyncTask ;
@@ -336,13 +337,28 @@ private void performAuthManagementRequest(
336
337
checkNotNull (customTabsIntent );
337
338
338
339
Intent authIntent = prepareAuthorizationRequestIntent (request , customTabsIntent );
339
- mContext . startActivity ( AuthorizationManagementActivity .createStartIntent (
340
+ Intent startIntent = AuthorizationManagementActivity .createStartIntent (
340
341
mContext ,
341
342
request ,
342
343
authIntent ,
343
344
completedIntent ,
344
- canceledIntent )) ;
345
+ canceledIntent );
345
346
347
+ // Calling start activity from outside an activity requires FLAG_ACTIVITY_NEW_TASK.
348
+ if (!isActivity (mContext )) {
349
+ startIntent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
350
+ }
351
+ mContext .startActivity (startIntent );
352
+ }
353
+
354
+ private boolean isActivity (Context context ) {
355
+ while (context instanceof ContextWrapper ) {
356
+ if (context instanceof Activity ) {
357
+ return true ;
358
+ }
359
+ context = ((ContextWrapper ) context ).getBaseContext ();
360
+ }
361
+ return false ;
346
362
}
347
363
348
364
/**
You can’t perform that action at this time.
0 commit comments