Reputation: 1
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.
Upvotes: 0
Views: 286
Reputation: 1006539
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.
Upvotes: 4