简体   繁体   中英

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.

@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
        }       
}

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

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