我要把一个对象从 activity 传递到 server 中。
Waveform waveform = new Waveform();
Intent intent = new Intent(this, StimulationService.class);
Bundle bundle = new Bundle();
bundle.putParcelable("test", (Parcelable) waveform);
intent.putExtras(bundle);
startService(intent);
Server 里的 onStart() 函数中的代码:
Bundle bundle = this.getIntent().getExtras();
if(bundle!=null)
mWaveform = bundle.getParcelable(waveform);
却获取 getParcelable() 中"getIntent" 和 "waveform" 的错误。怎么解决这个问题?
1.Services 里没有一个 getIntent 方法。相反 intent 作为一个 argument 传递到 onStart 中,所以你应该使用参数。
getParcelable 方法要调用一个 String,在你的例子中是"test"。