为什么System.out.println("mp3Info----->" + mp3Info); 打印出来的值是:
mp3Info----->Mp3Info [id=null, mp3Name=geinimen.mp3, mp3Size=4701110, lrcName=null, lrcSize=null]
代码:
class BeginButtonListener implements OnClickListener {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(PlayerActivity.this, PlayerService.class);
intent.putExtra("mo3Info", mp3Info);
System.out.println("mp3Info----->" + mp3Info);
intent.putExtra("MSG", AppConstant.PlayerMsg.PLAY_MSG);
startService(intent);
}
而传到Service里System.out.println("mp3Info111----->" + mp3Info);打印出来就是:mp3Info111----->null
代码:public int onStartCommand(Intent intent, int flags, int startId) {
Mp3Info mp3Info = (Mp3Info)intent.getSerializableExtra("mp3Info");
System.out.println("mp3Info111----->" + mp3Info);
int MSG = intent.getIntExtra("MSG", 0);
if (mp3Info != null) {
if (MSG == AppConstant.PlayerMsg.PLAY_MSG) {
play(mp3Info);
} else {
if (MSG == AppConstant.PlayerMsg.PAUSE_MSG) {
pause();
} else if (MSG == AppConstant.PlayerMsg.STOP_MSG) {
stop();
}
}
}
return super.onStartCommand(intent, flags, startId);
------解决方案--------------------
建议用Bundle
------解决方案--------------------
Bundle b = new Bundle();
b.putXXX(TAG, value);
intent.putExtra(b);
============================
intent.getExtra();
b.getXXXX(TAG);