如何从可序列化的对象中获取价值

时间:2018-07-24 09:58:31

标签: android serialization intentservice

我将serializable类型的对象通过BroadcastReceiverIntentService的{​​{1}}传递。 此代码已分配给BroadcastReceiver

BroadcastReceiver

但是我的问题是,Android Studio说 @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "onReceive: Received Broadcast: " + intent + " from context: " + context); RetrofitResponseProfile retrofitResponseProfile = intent.getSerializableExtra(NetworkService.NETWORK_RESPONSE_PROFILE); } 对象不是来自retrofitRepsonseProfile类型的对象。

有人可以帮助我,如何从serializable中的serializable接收IntentService对象吗?

非常感谢!

1 个答案:

答案 0 :(得分:3)

Your Class Should Be

Class RetrofitResponseProfile implements Serializable{
//Create Variables And Functions
}

And During Call

RetrofitResponseProfile retrofitResponseProfile = (RetrofitResponseProfile) intent.getSerializableExtra("Key0");

hope this may help you