android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:734)
at android.app.ContextImpl.startActivity(ContextImpl.java:721)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:345)
at net.openid.appauth.AuthorizationService.performAuthorizationRequest(AuthorizationService.java:230)
at net.openid.appauth.AuthorizationService.performAuthorizationRequest(AuthorizationService.java:132)
at com.janrain.android.engage.OpenIDAppAuthGoogle.makeAuthRequest(OpenIDAppAuthGoogle.java:185)
at com.janrain.android.engage.OpenIDAppAuthGoogle.access$100(OpenIDAppAuthGoogle.java:64)
at com.janrain.android.engage.OpenIDAppAuthGoogle$1.onFetchConfigurationCompleted(OpenIDAppAuthGoogle.java:122)
at net.openid.appauth.AuthorizationServiceConfiguration$ConfigurationRetrievalAsyncTask.onPostExecute(AuthorizationServiceConfiguration.java:331)
at net.openid.appauth.AuthorizationServiceConfiguration$ConfigurationRetrievalAsyncTask.onPostExecute(AuthorizationServiceConfiguration.java:272)
at android.os.AsyncTask.finish(AsyncTask.java:651)
at android.os.AsyncTask.access$500(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Reading the description line of the exception, it is possible you have provided a non-Activity context to the constructor of AuthorizationService.
Thanks for the reply. it is fixed
I think there should be a way to construct AuthorizationService outside Activity context. This is needed when you want to use AuthorizationService from service, without UI. For example background synchronization is one of those usecases. Then you only have application context available.
Currently it is not possible to customize how Intent is create as it is static method in AuthorizationManagementActivity:
private static Intent createBaseIntent(Context context) {
return new Intent(context, AuthorizationManagementActivity.class);
}
Working temporary fix:
private static Intent createBaseIntent(Context context) {
Intent intent =
new Intent(context, AuthorizationManagementActivity.class);
if (context == context.getApplicationContext()) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
return intent;
}
But maybe it would be better to provide a way to customize how Intents is created.
Same kind of problem exist with threads:
https://github.com/openid/AppAuth-Android/issues/123
there exists a good plan to solve that problem. Similar solution is needed for this; applications need a way to customize Intent.
Would you consider to provide an option to customize how Intent is created?
Most helpful comment
I think there should be a way to construct AuthorizationService outside Activity context. This is needed when you want to use AuthorizationService from service, without UI. For example background synchronization is one of those usecases. Then you only have application context available.
Currently it is not possible to customize how Intent is create as it is static method in AuthorizationManagementActivity:
private static Intent createBaseIntent(Context context) { return new Intent(context, AuthorizationManagementActivity.class); }Working temporary fix:
private static Intent createBaseIntent(Context context) { Intent intent = new Intent(context, AuthorizationManagementActivity.class); if (context == context.getApplicationContext()) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } return intent; }But maybe it would be better to provide a way to customize how Intents is created.
Same kind of problem exist with threads:
https://github.com/openid/AppAuth-Android/issues/123
there exists a good plan to solve that problem. Similar solution is needed for this; applications need a way to customize Intent.
Would you consider to provide an option to customize how Intent is created?