Skip to content

Commit

Permalink
Add FLAG_ACTIVITY_NEW_TASK when calling context is not an activity (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
SubSide authored and agologan committed Dec 7, 2021
1 parent d7f2ac9 commit 90f2233
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions library/java/net/openid/appauth/AuthorizationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
Expand Down Expand Up @@ -336,13 +337,28 @@ private void performAuthManagementRequest(
checkNotNull(customTabsIntent);

Intent authIntent = prepareAuthorizationRequestIntent(request, customTabsIntent);
mContext.startActivity(AuthorizationManagementActivity.createStartIntent(
Intent startIntent = AuthorizationManagementActivity.createStartIntent(
mContext,
request,
authIntent,
completedIntent,
canceledIntent));
canceledIntent);

// Calling start activity from outside an activity requires FLAG_ACTIVITY_NEW_TASK.
if (!isActivity(mContext)) {
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
mContext.startActivity(startIntent);
}

private boolean isActivity(Context context) {
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
return true;
}
context = ((ContextWrapper) context).getBaseContext();
}
return false;
}

/**
Expand Down

0 comments on commit 90f2233

Please sign in to comment.