简体   繁体   中英

Azure Mobile Services Android Error

I'm doing an android app and trying to integrate social login into the application using Azure Mobile Services.

public class SocialLogin extends Activity implements UserAuthenticationCallback {
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                   // on create code
            }

         // All the code

            @Override
            public void onCompleted(MobileServiceUser user, Exception exception, ServiceFilterResponse response) {
                if (exception == null) {
                    //Take user to the logged in view
                    cacheUserToken(user);
                } else {
                    Log.e("SocialLogin", "User did not login successfully");
                }
            }
}

I'm getting two errors because of the onCompleted method.

Error:(176, 5) error: method does not override or implement a method from a supertype
Error:(37, 8) error: SocialLogin is not abstract and does not override abstract method onCompleted(MobileServiceUser,Exception,ServiceFilterResponse) in UserAuthenticationCallback

Edit: Fixed the problem by deleting away the .jar file in my lib.

Per my understanding, 'UserAuthenticationCallback' is not an interface since many of samples are coding like this:

MobileServiceClient mClient = new MobileServiceClient(
            "MobileServiceUrl",
            "AppKey", 
            this).withFilter(new ProgressFilter());
mClient.login(MobileServiceAuthenticationProvider.MicrosoftAccount,
                new UserAuthenticationCallback() {
                    @Override
                    public void onCompleted(MobileServiceUser user,
                            Exception exception, ServiceFilterResponse response) {

                        synchronized(mAuthenticationLock)
                        {
                            if (exception == null) {
                                cacheUserToken(mClient.getCurrentUser());
                            } else {
                                createAndShowDialog(exception.getMessage(), "Login Error");
                            }

                        }
                    }
                });

Since it is not an interface, we cannot implement it as you did. You can either create a class that inherits UserAuthenticationCallback (but the class cannot inherit Activity as we can only inherit one class), or simply create a new instance of UserAuthenticationCallback like the code in the sample.

Also, I'd like to suggest you to check https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-get-started-users/ and https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-get-started-data/ for a completed sample of how to add authentication to your Mobile Services Android app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM