Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8886793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:38:39+00:00 2026-06-14T21:38:39+00:00

I am trying to follow Authenticating to OAuth2 Services and implement the part where

  • 0

I am trying to follow Authenticating to OAuth2 Services and implement the part where an Intent is included in the Bundle provided by the AccountManagerFuture#getResult() call.

The issue is, that even though the docs say to use Activity#startActivityForResult(…), the Intent I am told to fire apparently starts in its own task, resulting in onActivityResult being called immediately.

Another part which I am uncertain I am doing correctly is the way I launch this Intent. Because the code that calls AccountManager#getAuthToken(…) is buried inside a worker thread with no access to the current Activity, I am launching a new Activity I call “CredentialsActivity” which then launches the OS-provided Intent using startActivityForResult.

This is how I do that:

      final AccountManagerFuture<Bundle> future = AccountManager.getAuthToken(...);

      // Now that we have the Future, we extract the Bundle
      Bundle bundle = null;
      try {
        bundle = future.getResult();
      } catch (Exception e) {
        log.warn(e, "Got an Exception");
      }

      if (bundle == null) {
        log.info("Unable to get auth token");
        return;
      }

      // Check if the user needs to enter credentials.
      final Intent askForPassword = (Intent) bundle.get(AccountManager.KEY_INTENT);
      if (askForPassword != null) {
        log.dev("Need to prompt for credentials, firing Intent...");
        CredentialsActivity.promptForCredentials(context, askForPassword);
      }

These are the relevant parts of CredentialsActivity:

      private static final int REQUEST_CODE_LAUNCH_CREDENTIALS_INTENT = 0;

      private static Intent newCredentialsActivityIntent(Context context) {
        final Intent intent = new Intent(context, CredentialsActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        return intent;
      }

      public static void promptForCredentials(Context context, Intent credentialsIntent) {
        final Intent intent = newCredentialsActivityIntent(context);
        intent.putExtra(Intent.EXTRA_INTENT, credentialsIntent);

        context.startActivity(intent);
      }

I fire the Intent in onResume:

  @Override
  protected void onResume() {
    super.onResume();
    final Intent intent = getIntent();
    final Intent credentialsIntent = (Intent) intent.getParcelableExtra(Intent.EXTRA_INTENT);
    if (credentialsIntent != null) {
      startActivityForResult(credentialsIntent, REQUEST_CODE_LAUNCH_CREDENTIALS_INTENT);
    }
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:38:40+00:00Added an answer on June 14, 2026 at 9:38 pm

    OK, so I think I figured this one out – I’ll post the answer, just in case:

    The issue is that the system provides the Intent with the NEW_TASK flag set. I needed to clear it to make this work for me:

    final Intent credentialsIntent = (Intent) intent.getParcelableExtra(Intent.EXTRA_INTENT);
    if (credentialsIntent != null) {
      credentialsIntent.setFlags(0);
      startActivityForResult(credentialsIntent, REQUEST_CODE_LAUNCH_CREDENTIALS_INTENT);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to follow this turorial in order to implement openID authentication on
Trying to follow this example. (Section String sorting...) Is there anything obvious that would
Im trying to follow a tutorial that is using SBJsonParser to get twitter feeds,
I'm trying to follow these docs: http://readthedocs.org/docs/neo4j-rest-client/en/latest/indices.html This works fine from neo4jrestclient.client import GraphDatabase,
I'm trying to follow the steps to compile some C code to import into
I'm trying to follow along with Railscasts #235 (Omniauth in a rails app). Having
I'm trying to follow a tutorial on NodeJS. I don't think I missed anything
I am trying to follow this article to do the same for adding a
So I was trying to follow http://developer.android.com/guide/topics/media/camera.html to create a simple app that captures
I'm trying to follow this tutorial using StructureMap : http://iridescence.no/post/Constructor-Injection-for-ASPNET-MVC-Action-Filters.aspx What I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.