Sorry I can't understand what you are doing enough to help. If you have a static variable holding a singleton, it will hold whatever the last value you put into it is (until your process gets killed, and then of course the next time it is restarted it will be re-initialized to its default value). There is nothing about activities or anything else in Android that has an impact on this fundamental behavior.
On Sun, Sep 6, 2009 at 3:48 AM, indra <[email protected]> wrote: > > Hi, > Here I come across a strange problem. I am using a static list (say > myList) in a Singleton class, which I use in a activity (say > myActivity) which is run by a singleTask root activity (rootActivty). > But when i try to access myList in the myActivity, I do not get a > refreshed version of that myList, instead I get the value one which I > first time accessed in myActivity. > Strangle when I run this myActivity standalone I get correct values of > myList each time. > Please help me out. > Thanks and Regards > Indra > > > On Aug 25, 9:46 pm, Dianne Hackborn <[email protected]> wrote: > > Please read the documentation. As I said in my original post, this is > for > > when your activity gets killed while it is in the background. When you > > press back, the default implementation is to finish() the activity so > there > > is no longer any instance data. > > > > > > > > > > > > On Tue, Aug 25, 2009 at 6:57 AM, sdphil <[email protected]> > wrote: > > > > > hm... okay, so I check for null in my onCreate() method. > > > > > public void onCreate(Bundle savedInstanceData) { > > > if (savedInstanceData == null) { > > > // do everything I did before. > > > // show splash screen > > > super.onCreate(savedInstanceState); > > > } > > > } > > > > > However, now if I'm in my app, I click on "home", and then click on > > > the icon again, it behaves as expected, it simply brings the app back > > > in the expected state. If I hit "back" and then click on the icon > > > again, it behaves like I launched a brand new app - shows the splash > > > screen, etc... > > > > > On Aug 24, 11:24 pm, Dianne Hackborn <[email protected]> wrote: > > > > The simple fact that it is non-null tells you. And you can have > placed > > > > anything else you want in there in onSaveInstanceState() for whatever > > > other > > > > data you want to retain. See here: > > > > > >http://developer.android.com/guide/topics/fundamentals.html#actlife > > > > > > and here: > > > > > >http://developer.android.com/reference/android/app/Activity.html > > > > > > On Mon, Aug 24, 2009 at 10:51 PM, sdphil <[email protected] > > > > > wrote: > > > > > > > "You can use the state passed in to onCreate() to determine whether > > > > > you are starting for the first time or not." > > > > > > > How do I do that? > > > > > > > I'm looking at onCreate -- > > > > > > > public void onCreate(Bundle savedInstanceState) { > > > > > > > and I look at savedInstanceState, nothing jumps out at me... > > > > > > > On Aug 24, 10:39 pm, Dianne Hackborn <[email protected]> wrote: > > > > > > If you just want pressing back to not close the activity, just > catch > > > the > > > > > > BACK key and call Activity.moveTaskToBack() instead of letting it > do > > > the > > > > > > default behavior (of calling finish()). > > > > > > > > There is no need to use launchMode nor alwaysRetainTaskState. > > > > > > > > However, you DO need to deal with the normal lifecycle behavior > -- in > > > > > > particular, when you are in the background, regardless of how > this > > > > > happened, > > > > > > the system is free to kill your process, so when the user next > > > returns to > > > > > > your app a new instance of your activity will be created. You > can > > > use > > > > > the > > > > > > state passed in to onCreate() to determine whether you are > starting > > > for > > > > > the > > > > > > first time or not. > > > > > > > > Also, a "quit" menu on an android application is not normal, > > > expected, > > > > > nor > > > > > > desired. Please don't do it; there is no need. I think you will > > > have a > > > > > > much better time if you try to design your app to follow the kind > of > > > flow > > > > > > shown by the existing applications, rather than trying to make it > > > work > > > > > like > > > > > > a desktop application. > > > > > > > > For example: you could save your current state to persistent > storage > > > when > > > > > > the user leaves the app, and restore it when they return, so they > > > know > > > > > they > > > > > > will always come back to the same thing. If it makes for them to > > > > > actually > > > > > > throw away that state, you could have an option for them to reset > the > > > app > > > > > so > > > > > > they can decide to do that at the time they want, rather than > having > > > to > > > > > > decide earlier on to have this happen as a side-effect of some > > > unusual > > > > > > "quit" command. > > > > > > > > On Mon, Aug 24, 2009 at 10:16 PM, sdphil < > [email protected] > > > > > > > wrote: > > > > > > > > > I want my application to work like this: > > > > > > > > > 1. When the user launches the application, it starts up. > > > > > > > 2. When the user hits back, or home, the application is still > > > running > > > > > > > (although not visible). > > > > > > > 3. If the user hits "menu->quit" the application exits cleanly. > > > > > > > 4. If the user starts the application, hits "home" and selects > the > > > > > > > application icon *again*, I want it to bring up the existing > > > insance > > > > > > > of the application with whatever activity state it had before > it > > > left. > > > > > > > 5. I do not ever want more than one instance of my application > to > > > be > > > > > > > running (i.e. singleton). > > > > > > > 6. I always want to retain activity stack/state. when you come > > > back > > > > > > > into the application, it's like you never left. > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > > > <manifest xmlns:android=" > > >http://schemas.android.com/apk/res/android" > > > > > > > package="com.company.gui" > > > > > > > android:versionCode="1" > > > > > > > android:versionName="1.0"> > > > > > > > <application android:icon="@drawable/icon" > > > > > > > android:label="@string/app_name" > > > > > > > android:debuggable="true"> > > > > > > > <activity android:name=".Main" > > > > > > > android:launchMode="singleTask" > > > > > > > android:alwaysRetainTaskState="true" > > > > > > > android:label="@string/app_name" > > > > > > > android:screenOrientation="portrait" > > > > > > > > android:theme="@android:style/Theme.NoTitleBar"> > > > > > > > <intent-filter> > > > > > > > <action > android:name="android.intent.action.MAIN" /> > > > > > > > <category > > > > > > > android:name="android.intent.category.LAUNCHER" /> > > > > > > > </intent-filter> > > > > > > > </activity> > > > > > > > > > <activity android:name=".SplashScreen" > > > > > > > android:label="@string/app_name"> > > > > > > > </activity> > > > > > > > > > </application> > > > > > > > <uses-sdk android:minSdkVersion="3" /> > > > > > > > <uses-permission > android:name="android.permission.INTERNET"></uses- > > > > > > > permission> > > > > > > > </manifest> > > > > > > > > > my main activity onCreate() looks like this: > > > > > > > > > startActivityForResult( new Intent(this, > > > SplashScreen.class), > > > > > > > SPLASH_REQUEST_ID ); > > > > > > > new Thread() { > > > > > > > public void run() { > > > > > > > try { > > > > > > > Thread.sleep(4 * 1000); > > > > > > > > > // put initialization > stuff > > > > > here. > > > > > > > > > } catch (InterruptedException e) > { > > > > > > > e.printStackTrace(); > > > > > > > } > > > > > > > finishActivity( SPLASH_REQUEST_ID ); > > > > > > > } > > > > > > > }.start(); > > > > > > > > > setContentView(R.layout.main); > > > > > > > > > If I leave the application by hitting home and then selecting > the > > > icon > > > > > > > again, it starts with the splash screen again! > > > > > > > > > any ideas on how to best fix this? > > > > > > > > > tia. > > > > > > > > -- > > > > > > Dianne Hackborn > > > > > > Android framework engineer > > > > > > [email protected] > > > > > > > > Note: please don't send private questions to me, as I don't have > time > > > to > > > > > > provide private support, and so won't reply to such e-mails. All > > > such > > > > > > questions should be posted on public forums, where I and others > can > > > see > > > > > and > > > > > > answer them. > > > > > > -- > > > > Dianne Hackborn > > > > Android framework engineer > > > > [email protected] > > > > > > Note: please don't send private questions to me, as I don't have time > to > > > > provide private support, and so won't reply to such e-mails. All > such > > > > questions should be posted on public forums, where I and others can > see > > > and > > > > answer them. > > > > -- > > Dianne Hackborn > > Android framework engineer > > [email protected] > > > > Note: please don't send private questions to me, as I don't have time to > > provide private support, and so won't reply to such e-mails. All such > > questions should be posted on public forums, where I and others can see > and > > answer them.- Hide quoted text - > > > > - Show quoted text - > > > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ 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] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

