Fair enough argument. Perhaps the Intent class could have been made final.
On Tue, Jul 28, 2009 at 4:29 PM, Mark Murphy <[email protected]>wrote:
>
> R Ravichandran wrote:
> > I was experimenting with extending the Intent class but don't seem to
> > make it work properly. I am wondering if extending is even possible.
> > Here is the snippets.
> >
> > Code for custom intent:
> >
> > public class MyIntent extends Intent {
> >
> > private MyClass myClass;
> >
> > public MyIntent(String name, MyClass myClass) {
> > super(name);
> > this.myClass = myClass;
> > }
> >
> > public MyClass getMyClass() {
> > return myClass;
> > }
> >
> > }
> >
> >
> > Code for Intent broadcast:
> >
> > MyClass myClass = new MyClass();
> > Intent intent = new MyIntent("my_intent",myClass);
> > sendBroadcast(intent);
> >
> > Code for BroadcastReceiver.onReceive(Intent intent):
> >
> > MyClass myClass = null;
> > if(intent instanceof MyIntent) {
> > // do something
> > }
> > else {
> > // probelm...
> > }
> >
> > When this application runs, I don't see the MyIntent received properly.
> > In fact, 'intent instanceof MyIntent' seems to return false.
> >
> > What is wrong?
>
> Intents are designed to go between processes.
>
> Let's suppose that you were broadcasting a MyIntent, and it was received
> by another application, not written by you. Since it was not written by
> you and runs in its own process, it does not have access to the MyIntent
> class and therefore could not create an instance of that class.
>
> The Intent system uses some form of serialization (perhaps Parcelable)
> to transport Intents between processes. What your experiment
> demonstrates is that the same mechanism is used even within the same
> process.
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://twitter.com/commonsguy
>
> Android 1.5 Programming Books: http://commonsware.com/books.html
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---