K
K
Kirill2018-04-01 21:55:13
Android
Kirill, 2018-04-01 21:55:13

I add a new code, I break the old one, what is it?

I am writing code to save variables when changing screen orientation.

@Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        super.onSaveInstanceState(savedInstanceState);
        Log.i(TAG, "onSaveInstanceState");
        savedInstanceState.putInt(KEY_INDEX, mCurrentIndex);
        savedInstanceState.putBooleanArray(KEY_INDEX, array);  
    }

   if (savedInstanceState != null) {
            mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0);
            array = savedInstanceState.getBooleanArray(KEY_INDEX);
        }

Only one of these variables is saved, how can both variables be saved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2018-04-01
@AlexanderYudakov

Keys must be different for different variables.
And you have one key - KEY_INDEX.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question