简体   繁体   中英

Pass Activity to service

Need to pass Activity to Service. I am using

intent.putExtra("messagedialog", this.messageDialog)

to pass the activity.

However when i try to get the activity using

messageDialog = intent.getParcelableExtra("messagedialog");

it returns null .

Is there i am missing something.

Need to pass Activity to Service

Whatever problem you think you are going to solve this way, there is a better solution. You may wish to post a question on an Android developer support site , where you explain in detail how this service and this activity are supposed to interact.

Is there i am missing something

First, an Activity is not Parcelable .

Second, even if you attempt to implement Parcelable on Activity , passing data via Intent extras is not pass-by-reference, but rather pass-by-value. Your service would retrieve a useless, detached copy of the activity, not the actual activity that (perhaps) is running.

I need to show activity from which end developer can override. like he can overide color/font/layout

Have the client send your service a PendingIntent , such as via an Intent extra. Your service can then send() that PendingIntent when needed. The PendingIntent can point to an activity that the client chooses to be shown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM