Sending an object to a service through Intent without binding

后端 未结 3 1302
悲哀的现实
悲哀的现实 2021-02-13 05:07

Is is possible to send an object to an Android Service through an Intent without actually binding to the service? Or maybe another way for the Service to access Objects...

3条回答
  •  感情败类
    2021-02-13 06:04

    Like Bino said, you need to have your custom object implement the Parcelable interface if you want to pass it to a service via an intent. This will make the object "serializable" in an Android IPC-wise sense so that you can pass them to an Intent's object putExtra(String, Parcelable) call.

    For simple primitive types, there's already a bunch of setExtra(String, primitive type) methods. As I understand you, however, this is not an option for you which is why you should go for a Parcel.

提交回复
热议问题