Solawe,

so if i repeat your need :
-> 1 complex object has to be stored and retrieved when your app stop/
start
-> This object must be accessible in your program

If I were you I'll do the follwing
-> To store and retrieve your file, use java serialization mechanism.
You'll find a lot of information and tutorial on internet.
-> This class should be the singleton fo a singleton pattern

You should have a méthode getInstance like this:
public class A implements Serializable {
A a = null;
  public static A getInstance(){
    if (a = null){
      1/ first try to deserialize the persistence file
        ... I let you work here :-)

       2/ if the file does not exisits, for the first time for
instance:
       a = new A()
      }//end if
     return a;
   }//end method

  public save(){
 // save your class thanks to serialization in a file
  }
}//end class

You'll find infiormation on how to store file in locale application
context here :
http://code.google.com/android/devel/data.html

Every time you need to use your instance call A.getinstance()

Save with A.getinstance().save()

Rgds

C.

On Jul 25, 12:11 pm, solawe <[EMAIL PROTECTED]> wrote:
> Thank you hackbod,  Steve Oldmeadow  and 6real for your response;
>
> I've a question : can i acess to an object A stored in a Application
> object from a simple class java?
>
> because me i need to store an instance of a class A on starting of my
> android application,later this instance A must be accessed by other
> simple classes java included on my application.
>
> Thanks for your responses.
>
> On 25 juil, 07:47, 6real <[EMAIL PROTECTED]> wrote:
>
> > I don't know exactly what will be your final choice but you maybe
> > should think to implements a Singleton pattern :
>
> >http://radio.weblogs.com/0122027/stories/2003/10/20/implementingTheSi...
>
> > Personnaly I have a class named ConfigurationContext with only static
> > variables that are stored, for persistence with the preferences
> > mechanism (http://code.google.com/android/devel/data/preferences.html)
> > and :
> > in my first activity the class is loaded.
> > Then all is accessed trough static attributs
> > If one attribut is changed, then I saved the preferences.
>
> > I hope it could help you but I only need to store simple object like
> > strings/numbers or boolean.
>
> > C.
>
> > On Jul 25, 3:23 am, Steve Oldmeadow <[EMAIL PROTECTED]> wrote:
>
> > > On Jul 24, 6:33 pm, solawe <[EMAIL PROTECTED]> wrote:
>
> > > > Ok, thanks;
>
> > > > But i dont know when i declare this variable? you think that i must
> > > > declare it on the first activity of my application?
>
> > > You could create an Application object and store it there.  Have a
> > > look at android.app.Application.  It has an onCreate() that gets
> > > called when the Application is created, before any Activities.  If it
> > > is going to be accessed by Services you probably need to think about
> > >threading issues.
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to