如何使用意图调用方法 [英] How to call a method using intent
本文介绍了如何使用意图调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在调用intent活动时,是否有任何可能的方法来调用方法.当我使用意图调用从一种活动切换到另一种活动时,我只想显示特定的方法.
Is there any possible way to call a method at the time when call the intent activity. I want to display only particular method when i switch over from one activity to another using intent call.
推荐答案
在 Intent
中使用 extras
包.
Intent i = new Intent(...);
i.putExtra("your_condition", int_condition);
然后在 Intent
int_condition=getIntent.getIntExtra("your_condition");
现在您可以使用此了
if(int_condition==0)
{
//Call the method
}
else
{
//method you want
}
同样,您还有另一种选择,因为您可以将方法名称作为参数传递给您的 Intent
中,假设您要发送的 mathod_name
作为 extra
到 Bundle
Again there is another option for you as you can pass the method name as a parameter in your Intent
, assumes that you are sending mathod_name
as an extra
to the Bundle
String method_name=getIntent.getIntExtra("method_name");
Class<?> c = Class.forName("class name");
Method method = c.getDeclaredMethod (method_name, parameterTypes)
method.invoke (objectToInvokeOn, params)
这篇关于如何使用意图调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文