#onSaveInstanceState issue

86 messages · Page 1 of 1 (latest)

tame basin
#

Can somebody please help me to get my onSaveInstanceState working I've tried multiple things and none of them have worked can somebody else DM me or hop in a discord call with me?

real violetBOT
#

This post has been reserved for your question.

Hey @tame basin! Please use /close or the Close Post button 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.

stiff bone
#

You didn't yet say what specifically the issue is, right?

tame basin
#

this is my MainActivity.java code

stiff bone
stiff bone
tame basin
stiff bone
#

why do you have 20 lists? Can't you use a Map?

stiff bone
tame basin
stiff bone
#

but still - what exactly is the issue?

#

What happens? What do you expect to happen? How is that different?

stiff bone
#

oh no

#

I don't think that's a good idea when I'm on my mobile

tame basin
#

it opens in your browser

stiff bone
#

so what's the issue?

stiff bone
tame basin
#

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

stiff bone
tame basin
#

oh

stiff bone
tame basin
#

`@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?

stiff bone
#

But are you also loading it?

stiff bone
tame basin
#

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")); }

real violetBOT
#

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

tame basin
#

.

stiff bone
#

Is that code executed?

tame basin
#

All I want it to do is just load it when I go back into that category

stiff bone
#

also maybe you need to override onResume or similar

tame basin
#

Ok, thanks I will try that

stiff bone
#

onRestoreInstanceState

#

maybe that works

tame basin
#

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

stiff bone
#

feel free to do it whenever you have time

tame basin
#

Ok, thanks for the help so far

tame basin
#

@stiff bone have you used onRestoreInstanceState or onResume before and did it work in your project?

stiff bone
#

I don't do much with Android development

tame basin
#

Oh, so you haven't used Android Studio before?

stiff bone
#

I did use it a few times

tame basin
#

Sorry, I was just wondering if you were familiar with Android Studio

#

Just curious

real violetBOT
#

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

tame basin
#

I'm back

tame basin
#

@stiff bone how do I get rid of these errors '@layout/activity_main does not contain a declaration with id'

stiff bone
#

I think you can edit the xml and add a plus sign at the beginning of the id

tame basin
#

android:id="@+id/mainActivity"

stiff bone
#

yes

tame basin
#

i have this already

stiff bone
#

where are you getting the error?

deep sparrowBOT
#

'@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.

tame basin
#

'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);'

stiff bone
#

where is the layout yml file?

#

xml*

#

and what is it called?

tame basin
#

activity_main.xml

#

what do you mean where?

#

@stiff bone

stiff bone
#

where is the file stored?

#

ig it's something with res

tame basin
#

res\layout

stiff bone
#

can you click alt+enter on the error? What happens?

tame basin
#

suppress MissingInflatedId with an annotation

#

but the 'android:id="@+id/progressBar"' and the checkBoxes 1, 2, 3, 4 are in list_item.xml

tame basin
#

oh I needed to use this 'setContentView(R.layout.list_item);'

real violetBOT
#

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

tame basin
#

How do I put two different setContentView In the same onCreate is that even possible?

stiff bone
#

no but you can inflate different views

tame basin
#

that didn't work

tame basin
stiff bone
tame basin
#

ok, no problem its depreciated