Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login Callback Method Called Twice #1397

Closed
vinod1988 opened this issue Apr 21, 2017 · 5 comments
Closed

Login Callback Method Called Twice #1397

vinod1988 opened this issue Apr 21, 2017 · 5 comments

Comments

@vinod1988
Copy link

Please fill out the following details:

  1. Version of Mobile SDK Used: 5.0

  2. Issue found in Native App or Hybrid App: android native app

  3. OS Version: 4.0.3 and above

  4. Device: android

  5. Steps to reproduce: login and then call another activity (after login the activity called twice)

  6. Actual behavior: method called twice

  7. Expected Behavior: It should be call once, When the login is success

  8. Error Log:

    @OverRide
    public void onResume(RestClient client) {
    // Keeping reference to rest client
    this.client = client;
    // Show everything
    findViewById(R.id.root).setVisibility(View.VISIBLE);
    isLoggedIn = true;
    if (client != null) {

      }
    

}

@bhariharan
Copy link
Contributor

Yup - this is by design the first time login occurs.
Steps:

  • Kick off your MainActivity -> onResume is called.
  • onResume is where we attempt to fetch a valid RestClient.
  • This kicks off the login flow -> onPause is called and LoginActivity is launched.
  • Login process completes and finish is called on LoginActivity.
  • onResume is called on MainActivity -> This time there's a valid RestClient.

@vinod1988
Copy link
Author

Thanks for quick response.

Steps to replicate the issue in my app.

I have created the SplashActivity (this is my main activity) launch on first time install the application.

SplashActivity -----> if user is not logged in then its calling a LoginActivitity(Salesforce standard login). This time the onResume method called for my SplashActivity.

LoginActivity----> enter the valid username and password then onResume (SplashActvity called twice) and i am checking RestClient client is null or not if not null then passing the HomeActivity.

After few second the HomeActivity called twice. Let me know where is the loop whole or what mistake i am doing.

SplashActivity calling this method.

 @override
 public void onResume(RestClient client) {
         this.client = client;

           if (client != null  && this.client.getAuthToken() != null) {
             // here i am calling my HomeActivity class
         }

  }

Let me know what mistake i am doing. Can you please guide me for this. Thanks for your response.

@bhariharan
Copy link
Contributor

@vinod1988 Your onResume should look different. It should look more like this. We have base activities in the Mobile SDK such as SalesforceActivity for this purpose, to do all the heavy-lifting around account management for you. You can simply extend SalesforceActivity and onResume(RestClient client) will be called when a valid client is available post-authentication. This avoids the issues you're seeing around double calling. I'd recommend that path.

@vinod1988
Copy link
Author

vinod1988 commented May 25, 2017

@bhariharan Thanks for the reply. I am giving you the my SplashActivity blue print code. Let me know where i am doing the wrong.

public class SplashActivity extends SalesforceActivity implements 
          LoaderManager.LoaderCallbacks<JSONArray> {

private RestClient client;

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	// Setup view
	setContentView(R.layout.activity_splash_main);

}


@Override
public void onResume(RestClient client) {

    this.client = client;

	if (client != null  && this.client.getAuthToken() != null) {
                  // here i am calling my HomeActivity class
              }

    }
 }

This is my code that i have written inside the SplashActivity let me know where i am doing the wrong or not calling the proper method. @bhariharan Can u please guide me for this snippet code where i am doing the wrong. Thanks for your response.

@bhariharan
Copy link
Contributor

@vinod1988 This forum is reserved for known issues/bugs with our code. Please post other queries/discussions in our Google+ community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants