Activity之间调用成员方法
先贴代码吧,没什么可说的
public void callMethod(){try {//获取环境变量Context ctx = createPackageContext("com.forhope.zhang", Context.CONTEXT_IGNORE_SECURITY|CONTEXT_INCLUDE_CODE);//载入这个类Class clazz = ctx.getClassLoader().loadClass("com.forhope.zhang.MainActivity");//新建一个实例Object owner = clazz.newInstance();//调用方法,传入参数,得到结果clazz.getMethod("print", String.class).invoke(owner, "fuck");} catch (NameNotFoundException e) {e.printStackTrace();} catch (ClassNotFoundException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (InstantiationException e) {e.printStackTrace();} catch (SecurityException e) {e.printStackTrace();} catch (NoSuchMethodException e) {e.printStackTrace();} catch (IllegalArgumentException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();}}干嘛用的?