调用intent活动时是否有任何可能的方法来调用方法.当我使用intent调用从一个活动切换到另一个活动时,我想只显示特定的方法.
Tan*_*dal 12
使用中的extras包Intent.
Intent i = new Intent(...);
i.putExtra("your_condition", int_condition);
Run Code Online (Sandbox Code Playgroud)
然后on onCreate of the Intent
int_condition=getIntent.getIntExtra("your_condition");
Run Code Online (Sandbox Code Playgroud)
现在你可以使用它了
if(int_condition==0)
{
//Call the method
}
else
{
//method you want
}
Run Code Online (Sandbox Code Playgroud)
再次为您提供另一个选项,因为您可以将方法名称作为参数传递给您Intent,假设您要mathod_name作为参数发送extra给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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15272 次 |
| 最近记录: |