-1

I'm calling an Intent from an activity: I want to know what happens with the activity when I'm calling the Intent, I mean, is it destroyed? onPause? onStop?

This is what I use to call an Intent:

Intent intent = new Intent(context,class);
context.startActivity(intent);

I want to know that if I have a checkbox in an activity, so for example I check that checkbox and after I go to the next activity, but if I go back to the previous activity, the checkbox is not checked as it was when I call the Intent.
I don't know if I have explained my self, but I hope you can give me a hint to solve this.

mmmmmm
  • 32,227
  • 27
  • 88
  • 117
QuinDa
  • 918
  • 1
  • 12
  • 19

5 Answers5

1

By default, the activity is stopped, not destroyed. It might be destroyed if the system is low on resources.

So what's probably happening in your case is, the system gets low on resource so it destroys your activity. You should save your UI state in onSaveInstaceState, and restore it in onRestoreInstanceState. Read more here.

Jong
  • 9,045
  • 3
  • 34
  • 66
0

intent.putExtra("",""); Save chackbox state here

Artem Zelinskiy
  • 2,201
  • 16
  • 19
  • No, I don't want to have that information in the next activity, I want to have this checkbox checked if I go back to the previous activity. – QuinDa Dec 06 '12 at 17:21
0

Put state of checkbox in shared preferences or static variable and once you go back to that activity , check for its state and populate it if that is the case

v0d1ch
  • 2,738
  • 1
  • 22
  • 27
  • I am almost positive that one cannot rely on saving state in an activities static variables. I cannot find an official reference at the moment, but here is a good overall reference: http://developer.android.com/training/basics/activity-lifecycle/recreating.html. – Mike Dec 06 '12 at 18:35
  • From my experience so far every value i put in static stayed the same across activity lifecycle until the process itself is killed. See this discussion http://stackoverflow.com/questions/2475978/using-static-variables-in-android – v0d1ch Dec 06 '12 at 19:01
  • That sounds correct. In my case I normally want to save user inputs (e.g. status of checkboxes) in an activity across uses of the apps which could include the app being destroyed, so it was the prudent thing to not rely on static variables (to state the obvious). But in this case, static variables might be appropriate. Thanks for the comment. – Mike Dec 06 '12 at 20:43
0
I mean, is it destroyed? onPause? onStop?

onStop is called.

From developer.android.com

onStop() - Called when the activity is no longer visible to the user. 

Try saving the state of checkbox in static boolean with isChecked() and check that boolean in onRestart() - this is called, when you come back to your previous activity.

azizbekian
  • 60,783
  • 13
  • 169
  • 249
  • Yes, that's the solution I thought, but there are many check box and I didn't want to make lot's of IF. Is there another solution?? – QuinDa Dec 06 '12 at 17:47
  • Well, in that case you'd better look this post: http://stackoverflow.com/questions/9080682/how-do-i-make-a-checkbox-stay-in-the-same-state-every-time-i-open-my-app – azizbekian Dec 06 '12 at 17:51
0

There are numerous prior questions on saving the state of a checkbox (whether due to intent or screen rotation). The same generate approach applies:

For instance: How can I maintain the state of a CheckBox even after navigating to different activities in android?

And to determine the lifecycle calls being made, one can always override the methods with a call to super class and use breakpoints in the debugger. That has always been helpful to me to see the code in motion alongside the Android lifecycle diagrams.

Community
  • 1
  • 1
Mike
  • 777
  • 3
  • 7
  • 14