Android examples for java.lang.reflect:Method Invoke
Invoke method, Returns results if available, otherwise returns null.
//package com.java2s; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import android.util.Log; public class Main { /** Returns results if available, otherwise returns null. */ public static Object invokeMethod(Method method, Object receiver, Object... args) {//from w w w. j av a 2s . c o m try { return method.invoke(receiver, args); } catch (IllegalArgumentException e) { Log.e("Safe invoke fail", "Invalid args", e); } catch (IllegalAccessException e) { Log.e("Safe invoke fail", "Invalid access", e); } catch (InvocationTargetException e) { Log.e("Safe invoke fail", "Invalid target", e); } return null; } }