Can someone show a noob why my Bundle is always null?  The source of
my activity class is below, and I consistently get the following
debugging output:

DEBUG/Compass(18473): onCreate. bundle=null
DEBUG/Compass(18473): onResume
DEBUG/Compass(18473):   onSaveInstanceState, save bearing -1.0
DEBUG/Compass(18473): onResume
DEBUG/Compass(18473):   onSaveInstanceState, save bearing 191.37694
DEBUG/Compass(18473): onStop
DEBUG/Compass(18520): onCreate. bundle=null
DEBUG/Compass(18520): onResume
DEBUG/Compass(18520):   onSaveInstanceState, save bearing -1.0

This is AFTER leaving the app, doing lots of activity to make sure it
gets cleared from the stack, and returning.  Once I see that "save
bearing" line with something > -1, I expect to see a bundle in the
next onCreate.

Am I doing something goofy in my onSaveInstanceState?

Thanks for any help!

source:
============>

public class SimpleCompass extends Activity {

    private static final String TAG = "Compass";

    private DirectionNotifier directionNotifier;
    private SensorManager sensorManager;
    private CompassViewGroup viewGroup;

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        // TODO: WHY is bundle always null!?
        if (Config.LOGD) Log.d(TAG, "onCreate. bundle=" + bundle );

        // if( bundle != null && Config.LOGD ) { Log.d(TAG, "
containsKey=" + bundle.containsKey( BearingData.BEARING_KEY ) ); }
        if( bundle != null && bundle.containsKey
( BearingData.BEARING_KEY ) ){
                if (Config.LOGD) Log.d(TAG, "  bundle != null, bearing=" +
bundle.getFloat("bearing") );
                BearingData.setBearing( bundle.getFloat
( BearingData.BEARING_KEY ));
        }

        viewGroup = new CompassViewGroup(this);
        setContentView(viewGroup);
        directionNotifier = new DirectionNotifier( this );
        sensorManager = (SensorManager)getSystemService
(Context.SENSOR_SERVICE);
        directionNotifier.setViewGroup(viewGroup);
    }


    @Override
    protected void onResume()
    {
        if (Config.LOGD) Log.d(TAG, "onResume");
        super.onResume();
        sensorManager.registerListener(directionNotifier,
                        SensorManager.SENSOR_ORIENTATION,
                        SensorManager.SENSOR_DELAY_GAME);
    }

    @Override
    protected void onSaveInstanceState( Bundle bundle ){
        if (Config.LOGD) Log.d(TAG, "  onSaveInstanceState, save bearing
" + BearingData.getBearing() );
        if( bundle != null ){
                bundle.putFloat( BearingData.BEARING_KEY, BearingData.getBearing
() );
        } else {
                if (Config.LOGD) Log.d(TAG, "  onSaveInstanceState, bundle is
null!" );
        }
        super.onSaveInstanceState( bundle );
    }

    @Override
    protected void onStop()
    {
        if (Config.LOGD) Log.d(TAG, "onStop");
        sensorManager.unregisterListener(directionNotifier);

        directionNotifier = null;
        viewGroup = null;

        super.onStop();
        // finish();
    }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to