I want to extend my previous question.
If in my code there is a method provided by future API, also if I check the version I have the following warning in LogCat
04-24 09:30:12.565: I/dalvikvm(471): Could not find method android.view.ViewTreeObserver.removeOnGlobalLayoutListener, referenced from method com.my.project.ActivityHome.removeLayoutListenerPost16
04-24 09:30:12.565: W/dalvikvm(471): VFY: unable to resolve virtual method 2950: Landroid/view/ViewTreeObserver;.removeOnGlobalLayoutListener (Landroid/view/ViewTreeObserver$OnGlobalLayoutListener;)V
In my case (see linked question) I can resolve using reflection
try {
Method m = ViewTreeObserver.class.getMethod("removeOnGlobalLayoutListener", OnGlobalLayoutListener.class);
m.invoke(observer, listener);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
My question is: it is better to use reflection and avoid warning or I it is better to ignore warning avoiding reflection?
My reflection code doesn't catch exceptions, but I am not sure it is correct, is it?