2017-11-02 2 views
0

Ich verwende eine Methode mit boolescher Rückgabetyp für api 19, während meine App unterstützt min sdk 15, was wird die Methode zurückgeben, wenn die API weniger als 19 ist?Android @TargetApi zurückgeben

@TargetApi(19) 
    public static boolean isFeatureXEnabled(Context context) { 

    some logic 

    return true/false; 
} 

Was bekomme ich als Gegenleistung für API < 19 beim Aufruf?

classInstance.isFeatureXEnabled (Kontext);

Antwort

2

wollen wir verstehen, @TargetApi(19)

Sie eine Funktion verwenden, die auf mindestens SDK nicht verfügbar ist, so

Compiler : you cannot use this feature , it is not supported by min sdk 

You: i know what i am doing so hush , take this @TargetApi(19) 

Compiler : so now it is your responsibility to check the API level and call this function accordingly 

was wird das Verfahren Rückkehr einhüllen der api ist weniger als 19

Wenn der Code innerhalb dieser Funktion nicht von minsdk unterstützt wird, dann ist höchstwahrscheinlich ein Absturz andernfalls Ihr logisches Ergebnis

Ion

können Sie so etwas wie dies

@TargetApi(19) 
public static boolean isFeatureXEnabled(Context context) { 

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
     some logic 
     return true/false; 
    } 

    return false; 
} 
Verwandte Themen