Search code examples
androidandroid-activitylifecycle

Can I have two onNewIntent() in one Android activity?


I log in in my application with linkedin and twitter. These two client pass by a webview and come back in my application (I use onNewIntent() to get the data from them). The problem is: I can't have two onNewIntent() in one activity.. How can I do both of them in the same activity?

Here my code:

    @Override
protected void onNewIntent1(Intent intent2) {
    super.onNewIntent(intent2);
    Uri uri = intent2.getData();
    try {
        String verifier = uri.getQueryParameter("oauth_verifier");
        AccessToken accessToken = twitter.getOAuthAccessToken(requestToken,
                verifier);
        String token = accessToken.getToken(), secret = accessToken
                .getTokenSecret();

        System.out.println("ACCESSSSSSSS"+accessToken+token);
    } catch (TwitterException ex) {
        Log.e("Main.onNewIntent", "" + ex.getMessage());
    }

}


@Override
protected void onNewIntent(Intent intent) {

    String verifier = intent.getData().getQueryParameter("oauth_verifier");

    LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier);
    client = factory.createLinkedInApiClient(accessToken);
    client.postNetworkUpdate("LinkedIn Android app test");

    Person p = client.getProfileForCurrentUser(EnumSet.of(ProfileField.FIRST_NAME, ProfileField.LAST_NAME, ProfileField.ID));

    System.out.println("Token  "+accessToken.getToken());       
    System.out.println("Secret  "+accessToken.getTokenSecret());
    System.out.println("NOM: "+p.getLastName() + ", PRENOM: " + p.getFirstName());

    String user_id = p.getId();
    String first_name = p.getFirstName();
    String last_name = p.getLastName();
    String oauth_token = accessToken.getToken();
    String oauth_token_secret = accessToken.getTokenSecret();

    //Verification du login/password
    new LoginLinkedin().execute(user_id,oauth_token,oauth_token_secret,first_name,last_name);

    }

Solution

  • You cannot do this. Because onNewIntent must be overriden from the parent class the system will only 'see' the onNewIntent that actually overrides a parent method. The above code should cause a error because the use of the @Override method on onNewIntent1 is not valid.

    What you need to do is determine where the intent came from by observing its current data and then either running your twitter or linked in code. This observation should be made inside a single unified onNewIntent method.