给定代码:
public class CommandSequence {
public CommandSequence() {
}
public void startCommunications(View v) {
Bundle dataout1 = new Bundle();
dataout1.putInt("ACTION", Communications.ACTION_LOAD_COMMAND_ONLY);
dataout1.putInt("PORT", Commands.MESSAGE_TYPE_SMC);
dataout1.putInt("COMMAND", Commands.SMC_RESETEVENTSTATUS);
((MainActivity) v.getContext()).sendMessageToBackgroundCommunicationsService(
Communications.MESSAGE_LOAD_COMMAND,
dataout1);
}
}
我必须使用调用活动上下文(即“MainActivity”)转换“sendMessageToBackgroundCommunicationsService()”。
是否可以传递一个允许我在运行时强制转换方法调用的参数,以便可以从任何活动类调用此方法?