In my application I am trying to pass a generic worker object (which is parcelable) between activities. However, when I get parcelableExtra from intent, it creates new instance of the worker.
As you can see from the code, I assigned test variable to 10 then put it to bundle, when get it from new activity, it gives 15 as default value.
Is there a way to pass same instance reference between activities?
Put worker to intent:
fun newIntent(context: Context, worker: PlayerVideoContentsWorker, position: Int): Intent {
val intent = Intent(context, PlayerVideoContentsActivity::class.java)
worker.test = 10
intent.putExtra(WORKER, worker)
intent.putExtra(POSITION, position)
return intent
}
get worker from intent
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val worker = intent.getParcelableExtra<PlayerVideoContentsWorker>(WORKER)
print(worker?.test) //prints 15
...
PlayerVideoContentsWorker.kt
@Parcelize
class PlayerVideoContentsWorker(val service: PlayerPaginatableListService<VideoContent, CursorPagination>,
val paginationInfo: CursorPaginationInfo)
: PlayerPaginatableListWorker<VideoContent, CursorPagination>(service, paginationInfo), Parcelable
PlayerPaginatableListWorker
open class PlayerPaginatableListWorker<T : Parcelable, P : IPaginationData>(
private val service: PlayerPaginatableListService<T, P>,
private val paginationInfo: CommonPaginationInfo<P>) {
var test = 15
...