Android的新意图启动特定的方法 [英] Android New Intent start particular method
问题描述
我要开始我的现有活动之一,并迫使活动来调用特定的方法,它启动后。
这可能吗?
我可以定义一个应该创造我的意图在里面活动之后被调用的方法?
例如是这样的:
意向意图=新的意图(这一点,com.app.max.Home.class.myMethod);
没有,我不认为你可以有这样的事情 意向意图=新的意图(这一点,com.app.max.Home.class.method);
但你可以做到这一点。
意向意图=新的意图(这一点,com.app.max.Home.class);
intent.putExtra(方法名,myMethod的);
startActivity(意向);
然后在所谓的活动(如您需要启动方法)可以采取的意图,并决定调用哪个方法
@覆盖
保护无效onNewIntent(意向意图){
super.onNewIntent(意向);
如果(intent.getStringExtra(方法名)。等于(myMethod的)){
myMethod的();
}
}
I want to start one of my existing activities and force the activity to call a specific method after it started.
Is this possible?
Can I define a method that should be called after creating the activity inside my Intent?
For example something like:
Intent intent = new Intent(this, com.app.max.Home.class.myMethod);
No, I don't think you can have something like this Intent intent = new Intent(this, com.app.max.Home.class.method);
but you can do this
Intent intent = new Intent(this, com.app.max.Home.class);
intent.putExtra("methodName","myMethod");
startActivity(intent);
and then in the called activity (where you need to start the method) can take the intent and decide which method to call
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(intent.getStringExtra("methodName").equals("myMethod")){
mymethod();
}
}
这篇关于Android的新意图启动特定的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!