Lukas1
Lukas1

Reputation: 582

How to implement interface from newer Android API version

I'm working on a project that has minSdkVersion set to 7. Of course target SDK is newer, 18.

I'd like to use in my project interface Application.ActivityLifecycleCallbacks, but this is supported only from API level 14. I'm ok with not having that functionality for devices with older version of Android, still I'd like to use this interface to support newer devices with newer versions of API.

I'd be able to use Reflection or something similar if I were to only support a new class from newer API, but I don't know how to support a new interface. Can you point me somewhere? Thank you in advance.

Upvotes: 1

Views: 472

Answers (2)

Stan Smith
Stan Smith

Reputation: 906

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void myCustomMethod(){

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
                  // Your API level 14 code here
        }       
}

Upvotes: 4

Fred Grott
Fred Grott

Reputation: 3476

compose a wrapper that selects the calls to be made by Build SDK INT in some IF statements or use this third party lib:

https://github.com/BoD/android-activitylifecyclecallbacks-compat

Upvotes: 1

Related Questions