From: "Jason Simpkins" <[EMAIL PROTECTED]>
> I need to save the state of my app when the user exit it, simular to the
way
> memopad does.  My question is how is this done the "correct" way on the
> palm.

In AppStop(), save whatever info you need to restore your state in your
app's preferences.  In AppStart(), get the saved preferences if there are
any.  If there aren't any saved preferences, set default prefs.

For example:

static void AppStop( void )
{
  YourPreferenceType prefs;

  // get current state
  prefs.currentSomething = gSomething;
  // save current state
  PrefSetAppPreferences ( AppFileCreator, 0, AppVersion, &prefs,
    sizeof( YourPreferenceType ), true );

  FrmCloseAllForms ();
}

static Err AppStart( void )
{
  YourPreferenceType prefs;
  UInt16 prefSize;

  prefSize = sizeof( prefs );
  if ( PrefGetAppPreferences ( AppFileCreator, 0, &prefs,
    &prefSize, true ) != noPreferenceFound )
  {
    // store preferences in global vars
    gSomething = prefs.currentSomething;
  }
  else
  {
    // create default preferences & set globals
    gSomething = prefs.currentSometing = SomeDefault;
    PrefSetAppPreferences ( AppFileCreator, 0, 1, &prefs,
      sizeof( YourPreferenceType ), true );
  }
  return errNone;
}



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to