You are going to have to preserve your state either in that Bundle
that you get in onCreate or somewhere on the file system.  As several
other people on this thread have pointed out, you can't control the
lifecycle of your process and, by extension, your static finals.

Nor, btw, should you try.  Work with Android, not against it.  Think
about your application state, not the state of the process that
happens to power it, at the moment.  Calling System.exit() is icky, to
use a technical term.

You might want to have a look at this, for more discussion of the
issue:

http://portabledroid.wordpress.com/2012/05/04/singletons-in-android/


G. Blake Meike
Marakana

The second edition of Programming Android is now on-line:
http://shop.oreilly.com/product/0636920023005.do


On May 16, 12:03 pm, jon dattilo <[email protected]> wrote:
> Hi everyone,
>
> I'm working on developing my first real application beyond the basic
> tutorials. It is a fairly simple flashcard program for me to use in
> school and I have it up and running smoothly. It utilizes a set of
> variables to keep track of how many and which cards I have seen,
> nothing too fancy. However, sometimes when I switch to another
> application and come back to my program, it restarts everything, while
> in other instances it will pick up where the program left off. There
> doesn't seem to be any pattern to when the program resets, and I don't
> have any task killer software installed that would end the program
> without my knowledge.
>
> I am inquiring how I tell the program to simply continue running in
> the background, and then if there is a function I can insert to "quit"
> the program so I can assign that to a button? I posted the start up
> code below, and would be happy to post more if someone could direct me
> to what would be relevant. As you can see I have it programed to go to
> the app's home screen when the app loads for the first time, which
> works if the app has quit and is restarting, but in most circumstances
> it resumes the flashcard portion, almost as if you had loaded the
> program and pressed the resume button from the home screen (which is
> what I want to happen all the time). I would be fine with loading the
> home screen every time someone switched out of the application, as
> long as the variables didn't reset when that happens. Any advice would
> be much appreciated.
>
> @Override
> public void onCreate(Bundle savedInstanceState){
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.home);
>         goHome();
>
> }
>
> public void goHome(){ //defines the home screen
>         setContentView(R.layout.home);
>
>     final Button instructionButton = (Button)
> findViewById(R.id.instructionButton);
>     instructionButton.setOnClickListener(this);
>
>     final Button newButton = (Button) findViewById(R.id.newButton);
>     newButton.setOnClickListener(this);
>
>     final Button resumeButton = (Button)
> findViewById(R.id.resumeButton);
>     resumeButton.setOnClickListener(this);
>
>     final Button reviewButton = (Button)
> findViewById(R.id.reviewButton);
>     reviewButton.setOnClickListener(this);
>
>
>
>
>
>
>
> }

-- 
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

Reply via email to