11 messages in com.googlegroups.android-developers[android-developers] Re: how can i sa...| From | Sent On | Attachments |
|---|---|---|
| solawe | 23 Jul 2008 06:27 | |
| hackbod | 23 Jul 2008 09:57 | |
| solawe | 24 Jul 2008 03:33 | |
| hackbod | 24 Jul 2008 15:48 | |
| Steve Oldmeadow | 24 Jul 2008 18:23 | |
| 6real | 25 Jul 2008 00:46 | |
| solawe | 25 Jul 2008 03:10 | |
| 6real | 25 Jul 2008 03:30 | |
| solawe | 25 Jul 2008 05:58 | |
| Steve Oldmeadow | 25 Jul 2008 19:23 | |
| 6real | 28 Jul 2008 04:35 |
| Subject: | [android-developers] Re: how can i save a class instance in the android application context![]() |
|---|---|
| From: | 6real (cyri...@gmail.com) |
| Date: | 07/25/2008 03:30:47 AM |
| List: | com.googlegroups.android-developers |
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 <ikra...@gmail.com> 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 <cyri...@gmail.com> wrote:
I don't know exactly what will be your final choice but you maybe should think to implements a Singleton pattern :
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 <st....@smoco.com> wrote:
On Jul 24, 6:33 pm, solawe <ikra...@gmail.com> 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 andr...@googlegroups.com To unsubscribe from this group, send email to andr...@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---




