我有一个这样的接口:我可以将接口传递给android中的服务吗?
public interface MyInterface {
public void aMethod();
}
我的自定义活动:
public class MyObject extends Activity {
private Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
start(5,MyInterface handle);
}
public void start(final int duration, MyInterface handle){
Intent intent = new Intent(getApplicationContext(),myService.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle bundle = new Bundle();
//Eroor !*** i can't pass handle.aMethod() to my service ***
bundle.putSerializable("handle",bundle.getSerializable(handle.aMethod()));
intent.putExtras(bundle);
startService(intent);
}
}
我有一个服务:
public class myService extends Service {
}
我想实现我的接口方法,在我服务。我的活动传递接口方法来服务并启动它。
我无法将handle.aMethod()传递给我的服务。
如何将接口传递给活动方法中的服务?
为什么你想通过'接口到服务'? –
你应该到这个http://stackoverflow.com/questions/28611527/passing-data-from-activity-to-service-through-interface –
好像你要拨打的服务接口方法? –