#onSaveInstanceState issue
86 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @tame basin! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
You didn't yet say what specifically the issue is, right?
it isn't saving like it's suppose to
this is my MainActivity.java code
what exactly is different from what's supposed to happen?
did you delete the message?
I would like to talk in here @stiff bone
why do you have 20 lists? Can't you use a Map?
I can't/don't really want to talk in a VC right now
It didn't work for me using HashMaps
but still - what exactly is the issue?
What happens? What do you expect to happen? How is that different?
it opens in your browser
so what's the issue?
I have used codetogether in the past
my program for some for some reason doesn't save my checkboxes and progress bars when I go to a different category then go back
that's what I meant lol
oh
Do you use the savedInstanceState in your onCreate?
`@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
ProgressBar progressBar = findViewById(R.id.progressBar);
CheckBox checkBox1 = findViewById(R.id.checkBox1);
CheckBox checkBox2 = findViewById(R.id.checkBox2);
CheckBox checkBox3 = findViewById(R.id.checkBox3);
CheckBox checkBox4 = findViewById(R.id.checkBox4);
outState.putInt("progressBarValue", progressBar.getProgress());
outState.putBoolean("checkBox1Value", checkBox1.isChecked());
outState.putBoolean("checkBox2Value", checkBox2.isChecked());
outState.putBoolean("checkBox3Value", checkBox3.isChecked());
outState.putBoolean("checkBox4Value", checkBox4.isChecked());
}`
do you mean this?
that's saving the data
But are you also loading it?
that's just taking the values and storing them somewhere
I load it here
if (savedInstanceState != null) { progressBar.setProgress(savedInstanceState.getInt("progressBarValue")); checkBox1.setChecked(savedInstanceState.getBoolean("checkBox1Value")); checkBox2.setChecked(savedInstanceState.getBoolean("checkBox2Value")); checkBox3.setChecked(savedInstanceState.getBoolean("checkBox3Value")); checkBox4.setChecked(savedInstanceState.getBoolean("checkBox4Value")); }
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
.
Does that not do anything?
Is that code executed?
All I want it to do is just load it when I go back into that category
Is that code executed when going back?
also maybe you need to override onResume or similar
Ok, thanks I will try that
Oh ok
I'm not currently working on it right now because I have to leave for school in a little bit but after 3 o'clock after I get done with work I will be working on it
feel free to do it whenever you have time
Ok, thanks for the help so far
@stiff bone have you used onRestoreInstanceState or onResume before and did it work in your project?
I might have used it at some point idk
I don't do much with Android development
Oh, so you haven't used Android Studio before?
I did use it a few times
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
I'm back
@stiff bone how do I get rid of these errors '@layout/activity_main does not contain a declaration with id'
I think you can edit the xml and add a plus sign at the beginning of the id
android:id="@+id/mainActivity"
yes
i have this already
where are you getting the error?
'@Override ```java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner classes = findViewById(R.id.sp_classes);
EditText MWIII = findViewById(R.id.text_mwiii);
Chip mwiiiChip = findViewById(R.id.MWIIIChip);
ListView mwiii = findViewById(R.id.mwiii);
EditText MWII = findViewById(R.id.text_mwii);
Chip mwiiChip = findViewById(R.id.MWIIChip);
ListView mwii = findViewById(R.id.mwii);
Chip resetChip = findViewById(R.id.resetChip);
ProgressBar progressBar = findViewById(R.id.progressBar);
CheckBox checkBox1 = findViewById(R.id.checkBox1);
CheckBox checkBox2 = findViewById(R.id.checkBox2);
CheckBox checkBox3 = findViewById(R.id.checkBox3);
CheckBox checkBox4 = findViewById(R.id.checkBox4);
if (savedInstanceState != null) {
progressBar.setProgress(savedInstanceState.getInt(PROGRESS_BAR_VALUE_KEY));
checkBox1.setChecked(savedInstanceState.getBoolean(CHECK_BOX_1_VALUE_KEY));
checkBox2.setChecked(savedInstanceState.getBoolean(CHECK_BOX_2_VALUE_KEY));
checkBox3.setChecked(savedInstanceState.getBoolean(CHECK_BOX_3_VALUE_KEY));
checkBox4.setChecked(savedInstanceState.getBoolean(CHECK_BOX_4_VALUE_KEY));
}' ```
This message has been formatted automatically. You can disable this using /preferences.
'ProgressBar progressBar = findViewById(R.id.progressBar);
CheckBox checkBox1 = findViewById(R.id.checkBox1);
CheckBox checkBox2 = findViewById(R.id.checkBox2);
CheckBox checkBox3 = findViewById(R.id.checkBox3);
CheckBox checkBox4 = findViewById(R.id.checkBox4);'
res\layout
can you click alt+enter on the error? What happens?
suppress MissingInflatedId with an annotation
but the 'android:id="@+id/progressBar"' and the checkBoxes 1, 2, 3, 4 are in list_item.xml
oh I needed to use this 'setContentView(R.layout.list_item);'
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
How do I put two different setContentView In the same onCreate is that even possible?
no but you can inflate different views
that didn't work
I don't even know what getCsllId is supposed to be so I can't tell you about equivalent methods
ok, no problem its depreciated