extend Parcelable?

by Craig » Wed, 29 Oct 2008 23:14:33 GMT

Sponsored Links
 I have a class that extends a class that implements Parcelable. I have
instances of both classes in my app, and I would like to have the
subclass rely on the superclass' parceling methods for reading and
writing the superclass' variables, with the subclass only handling its
own extension.

It looks like there used to be a readFromParcel method on Parcelable
which would have suited my purpose, but with a static
Parcelable.Creator I'm not sure how to do it?

Anyone figure this out already?


extend Parcelable?

by Craig » Fri, 31 Oct 2008 00:24:05 GMT

 To answer my own question, I have what looks like a workable solution,
but I don't love it. Please add your improvements and offer better
suggestions, but I'd like to keep this conversation going.

I added a private no arg ctor to the superclass. The createFromParcel
method calls this, and then calls a static method on the superclass
that takes parameters of that class and a parcel. Subclass
Parcelable.CREATORs can do the same thing - create their own instance
and then call the superclass.setValues and pass the instance it is
creating. There isn't an issue writing the parcel - you can just call

This doesn't seem very elegant, and it may be slightly slower.

I may have 1 big class instead of splitting it up...

Sponsored Links

Other Threads

1. how can i get latitude and longitude?


I am really a beginner and this is the code I am running to get
latitude and longitude...

package com.GPSAndroid;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;

public class GPSAndroid extends Activity{

        private LocationListener myLocationListener;
    private LocationManager myLocationManager;
    public String latitude, longitude;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        myLocationManager = (LocationManager)getSystemService
                myLocationListener = new MyLocationListener();

(LocationManager.GPS_PROVIDER, 1, 1, myLocationListener);

// latitude=String.valueOf(myLocationManager.getLastKnownLocation
      //  Log.v("GPS","GPS latitude:"+latitude);


   public class MyLocationListener implements LocationListener{

        public void onLocationChanged(Location argLocation) {
                if(argLocation != null){
                        latitude = String.valueOf(argLocation.getLatitude());
                        longitude = String.valueOf(argLocation.getLongitude());
        public void onProviderDisabled(String provider) {

        public void onProviderEnabled(String provider) {

        public void onStatusChanged(String provider, int status, Bundle
arg2) {



But when I uncomment latitude line I got error? What do I do wrong?


2. Can I use an old Android phone for development purposes?

GPS is not dependent on a carrier network. You could get a prepaid sim
card and put it in your device. If you run out of minutes, you should
be still able to use the triangulation method in case you don't want
to use GPS.

Roman Baumgaertner
Sr. SW Engineer-OSDC
T  Mobile stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.


3. Android 2.0 SDK & Bluetooth

4. Cannot debug using emulator with DROID skin

5. Fetching Android system software version

6. Error when trying HelloTimePicker Android Tutoral

7. android WiFi