I am having trouble finding out how to maintain the state of my Android app in development.
Just to clarify, I am not talking about maintaining activity state (i.e.
As I understand the question you want to launch your application and have a different thing happen each time depending on where you left off the last time. http://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks.html The activity lifecycle is in the link. Your onActivityDestroyed method somehow needs to persist the present state and the oncreate needs to pick it back up. Persistence can be achieved via shared preferences, stored in a file, database or over the network http://developer.android.com/guide/topics/data/data-storage.html This unpredictable behavior could cause confusion for the end user if poorly implemented so use good judgement.
"However, if I choose to run my app again, it should take me to activity B, which is where I left off before pressing the home button, but instead it is taking me to activity A."
Yes, it should. If it isn't, you have done something in your app to tell the platform to modify its behavior. (Look at ApiDemos as an example, it uses the standard behavior, which is what it sounds like you are describing as what you expect.)
Things to look out for:
You're imagining there's something called an "Application" but that's an illusion. Your application is just a collection of Activities, Services, Receivers, etc.
If you look at the intent-filter
tags in your manifest, you'll see that each icon in the home screen is associated with a filter like this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
You can put that same chunk of XML on both of your Activities, and you'll get two icons in the home screen, one that always launches Activity A, and one that always launches Activity B.
What you may want to do instead is create a master Activity that launches one of the other Activities based on the shared state.
As for where to actually store the shared state, that depends on how complex your state is. This is a good place to start: http://developer.android.com/guide/topics/data/data-storage.html