在调用 Intent Activity 时是否有任何可能的方法来调用方法。当我使用 Intent 调用从一个 Activity 切换到另一个 Activity 时,我只想显示特定的方法。
最佳答案
在 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
作为 额外发送
到 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)
关于android - 如何使用 Intent 调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5946171/