Monday, September 26, 2011

Re: [android-developers] unmarshalling and premature alarm problems


Hi,

Now I see what you mean. So these bundle objects are better than parcels
to pass things around. Still don't understand why parcelable isn't working
since my process was still around when I called it in some cases.

Anyways, besides designing parcelable as a performance improvement
over serializable I'm still puzzled by why the android team had to come
up with both bundles and parcels and not just have say bundles.

Also, if an application has a unique context, then does a context correspond
to a process? I see context passed around as a parameter a lot, but don't
understand exactly what I am passing and why. It seems to me I keep on
passing the same thing around. Or does each activity have a different
context. Please help coming to grips with these presumably simple
concepts.

Finally, I think as an alternative to using the Bundleable interface described below I think
it is also possible to pass parameters around by storing them in an SQLite database since
most applications will already have one. Any disadvantages with this alternative approach
(which at least should work not only when the process is killed but also across reboots???)

Feedback and thoughts more than welcome,

Regards,

John Goche

On Mon, Sep 26, 2011 at 10:00 PM, TreKing <trekingapp@gmail.com> wrote:
  On Mon, Sep 26, 2011 at 2:40 PM, John Goche <johngoche99@googlemail.com> wrote:
Google "parcelable ClassNotFoundException" for more information.

What I've done is create a "Bundleable" interface that basically does what Parcelable is intended to do. Objects extending this interface can put themselves and recreate themselves from a Bundle object, which is itself Parcelable so you can send it around just like your object - except with the minor fact that the system always knows how to load a Bundle type so you don't run into this error.

Hmmm... Not sure I follow. Could you please give some more details?

public interface Bundleable
{
 public Bundle toBundle();

 public void fromBundle(Bundle b);
}

public class MyClass implements Bundleable
{
 public Bundle toBundle()
 { 
  Bundle b = new Bundle();
  // Fill b with data
  return b;
 }

 public void from Bundle(Bundle b)
 {
  // set properties from data in b
 }
}

// ...

MyClass m = new MyClass();
Intent i = new Intent();
i.putBundleExtra("MyClass", m.toBundle());

// ... Elsewhere

Bundle b = intent.getBundleExtra("MyClass");
MyClass m = new MyClass(b); // Constructor calls fromBundle(b);

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment