Robertoq
Robertoq

Reputation: 704

Android: call method of overrided class from library

In this example I have an app which is playing mp3 songs, but there are different license checks by companies.

So in my library I have 3 files:

public interface UserCheckerInterface {
    public void appIsEnabled(boolean result);
}

public class UserChecker {

    public static void appisEnabled(final UserCheckerInterface userCheckerInterface) {
         userCheckerInterface.appIsEnabled(true);
    }

}

public class MainActivity extends Activity {

    @Override
    public void onCreate(final Bundle savedInstanceState) {

         ....

         UserChecker.appisEnabled(new UserCheckerInterface(

             @Override
             public void appisEnabled(final boolean result) {
                 Toast.makeText(getApplicationContext(), "" + result, 0).show();
             }

         )); 

    }

}

I would like override the UserChecker.appisEnabled method in my app which is using this library, but I don't know how.

Upvotes: 0

Views: 260

Answers (1)

test
test

Reputation: 2618

I am not sure whether I have understood your question, if I did, than you simply have to implement your interface by writing

public class UserChecker implements UserCheckerInterface{

    @Override
    public static void appisEnabled(final UserCheckerInterface userCheckerInterface) {
         userCheckerInterface.appIsEnabled(true);
    }

}

Once you do that, then the IDE will show you an error IF you have not implemented the method; which is not the case in this scenario.

Upvotes: 1

Related Questions