Questions tagged [android-savedstate]

For questions related to Android's onSaveInstanceState and onRestoreInstanceState methods.

197 questions
1
vote
1 answer

Kotlin Android - saving mutableMap in savedInstanceState?

Is there a way to save map/mutableMap into savedInstanceState? other than using ViewModel functions. I'm curious to know his point... thanks in advance
1
vote
1 answer

Android ViewModel with SavedState rewrites arguments for new instances

I have an app which is having Master/Detail kind of architecture. When I select some item, the details are displayed in details fragment. For the detail fragment to know what to load id is sent over via Arguments. Using SavedStateHandle in VM I can…
1
vote
2 answers

ArrayList gets destroyed when fragment is switched to any other fragment or if app is closed and run again

In my android app, I have a navigation view which contains 5 fragments. In one fragment, I have an array list which is displayed in a list view, when I open the fragment it works fine, but when I change this fragment to any other fragment or close…
1
vote
0 answers

Android crash on orientation change

I have a android.widget.Spinner inside an androidx.fragment.app.Fragment. The spinner's items are dynamic and computed at runtime. override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ):…
digory doo
  • 1,978
  • 2
  • 23
  • 37
1
vote
1 answer

onRestoreInstanceState not working for RecyclerView layout manager if using Paging 3 library

I had a problem in saving RecyclerView state and it solved by saving layout manager state and using it after resume fragment.(thanks to @HarisDautović) class TestFragment : Fragment() { private val testListAdapter: TestListAdapter by lazy { …
1
vote
0 answers

Pass params from fragment to ViewModel Kotlin

I use SavedStateHandle to pass data between different components. My fragment use SavedStateViewModelFactory to initialize my VM (is it correct the initalization?) and a method in companion object to update the savedState. My…
1
vote
1 answer

Android OnCreate input bundle always null

I am undertaking project but I have been having some issues with activities and saving state. So I have gone back to basics to try and understand what I was missing. However, even with a very simple set up I am having the same issues. So I started…
1
vote
1 answer

ViewModel SavedStateHandler.get for LiveData can't set default value as per the document?

In referring to https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle#getLiveData(java.lang.String,%20T) The sample codes in Java as below. String defaultValue = ...; // nullable LiveData liveData; if (defaultValue…
1
vote
0 answers

How to put and get a list of strings to Bundle in Kotlin

Assume there is list of strings like val list = listOf("a", "b") How do I save it into and get from Bundle in Kotlin? I've tried saving like this but it gives the type mismatch error outState.putStringArrayList(KEY, list.toTypedArray()) Type…
yaugenka
  • 2,602
  • 2
  • 22
  • 41
1
vote
1 answer

onSaveInstanceState is called, but savedInstanceState in onCreate method throws null

put some serializable values to savedinstancestate, but savedInstanceState is null. onSaveInstanceState() is called with the log message, Code runs correcctly, but in onCreate method the null pointer is catched after restore the data and the saved…
1
vote
2 answers

How do I update my static context value saved from shared preferences?

I am planning to implement an easter egg to change my API through an alertdialog, but currently after I change my url endpoint and submit it it saves it in shared preferences, but next time i save it, it does save it in shared preferences ,but…
user2386226
1
vote
0 answers

Saving selected item from ListView when app closes and restarts again

Currently when the user selects an item from the listview with the function onItemClick, I am able to successfully get the data and load it into other fragments but when the app closes by the user closing in the task manager, the user has to go into…
Sahil Bora
  • 173
  • 1
  • 12
1
vote
0 answers

FATAL EXCEPTION: main Process: com.empowered.healo, PID: 28143 io.reactivex.exceptions.CompositeException: 2 exceptions occurred.?

I am developing a new app and I am getting two exceptions below. I have been trying to solve almost a day but I cant find any solution to this java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at…
1
vote
2 answers

What is the difference between saving with savedInstance and the fragment's argument?

In Android Fragment it has onSaveInstanceState() which allows to save some data for restore the state when os recreates the fragment. onSaveInstanceState(outState: Bundle) { outState.putString("dataStr", dataStr) } What about the data are…
lannyf
  • 9,865
  • 12
  • 70
  • 152
1
vote
1 answer

Replace fragment clears all Edittext Value

Inside Select Case I used this getFragmentManager().beginTransaction() .replace(R.id.frame_entry, new fragment_1()) .addToBackStack(null) .commit(); to switch between fragments, but I have a problem with it. The fragment contains EditText with a…
myown email
  • 139
  • 1
  • 10