When it is in the background, Android kills your application when it needs
more resources. One way to keep your data would be to write it to
SharedPreferences in onPause(), and read it from the same in onResume().

http://developer.android.com/reference/android/content/SharedPreferences.html

Thanks

On Thu, May 17, 2012 at 12:33 AM, 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




-- 
Raghav Sood
Please do not email private questions to me as I do not have time to answer
them. Instead, post them to public forums where others and I can answer and
benefit from them.
http://www.appaholics.in/ - Founder
http://www.apress.com/9781430239451 - Author
+91 81 303 77248

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