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 <hack...@android.com> 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 <phil.pellouch...@gmail.com> 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 <hack...@android.com> 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 <phil.pellouch...@gmail.com> > > 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 > > > hack...@android.com > > > > 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 > hack...@android.com > > 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---