Questions tagged [android-savedstate]

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

197 questions
44
votes
8 answers

Checking if state is saved before committing a FragmentTransaction

I sometimes see the following stacktrace for a commit that can happen when the user isn't looking at the activity (after state's been saved): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at…
21
votes
3 answers

ClassNotFoundException when unmarshalling android.support.v7.widget.Toolbar$SavedState

I am seeing the following error in my Android crash reports: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.v7.widget.Toolbar$SavedState at…
Aalap
  • 2,847
  • 2
  • 26
  • 24
20
votes
2 answers

How to prevent editText from auto filling text when fragment is restored from saved instance?

I have an activity which holds and shows multiple fragments. When i re-enter the fragment it auto fills text in all the editTexts. The same text for all fields as well. Example: Open fragment and fill in text in the two editTexts: CustomEditText1:…
19
votes
3 answers

How do I use the new Saved State Module of ViewModel

I'm using lifecycle version 2.2.0-rc03 and the official docs and articles found don't even list the correct class name or constructor arguments. I think I have to get the ViewModel instance through something like this viewModel =…
Steve M
  • 9,296
  • 11
  • 49
  • 98
17
votes
2 answers

Android View - What is automatically saved and restored in an Activity

I am a beginner with Android. In Android, some generic elements can be automatically saved/restored in onSaveInstanceState/onRestoreInstanceState. For example, an EditText saves/restores the Text property, a RatingBar saves/restores the Rating…
vernou
  • 6,818
  • 5
  • 30
  • 58
15
votes
3 answers

Android Fatal Error - Can not perform this action after onSaveInstanceState

I'm attempting to perform a fragment transaction after requesting permissions in Android - however the app continually crashes. How might this code be changed in order to avoid this? Any assistance is appreciated. CHECK PERMISSIONS BEFORE SENDING…
10
votes
5 answers

Android Activity instance state

What is the significance of: super.onCreate(null); instead of super.onCreate(savedInstanceState); With this change, I am able to avoid many problems that otherwise plague my Activitys each time a configuration change occurs (rotation, locale…
8
votes
0 answers

Is SavedStateHandle in ViewModel and currentBackStackEntry the same?

I want to pass some data using savedStateHandle from activity straight to fragment's viewModel. In my activity I have: navController.addOnDestinationChangedListener { controller, _, _ -> controller.currentBackStackEntry?.savedStateHandle?.set( …
8
votes
4 answers

How to save LiveData into saveStateHandle?

As shown in https://stackoverflow.com/a/61166665/3286489, we could save LiveData in savedStateHandle. I could do that easily https://stackoverflow.com/a/61166665/3286489 private val textLiveData: MutableLiveData init { textLiveData =…
8
votes
1 answer

SavedStateHandle returning null values

I have an ActionBar menu icon that opens a CategoryFragment. This fragment takes in a category object SafeArgs argument passed from another fragment. In the CategoryFragment, I store the category's name and id into the fragment's shared ViewModel as…
8
votes
2 answers

Restore state of view before applying XML attributes

I have a custom view, let's say this is its code: public class CustomView extends View { boolean visible; boolean enabled; public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { …
Nicolas
  • 6,611
  • 3
  • 29
  • 73
6
votes
2 answers

How to lazily save ViewModel's SavedStateHandle?

I have a screen that loads a bunch of requests and collects some data from the user on the same screen and an external WebView. Therefore, I have a ViewModel that contains these complex request objects (+ user input data). I need to persist this…
A1m
  • 2,897
  • 2
  • 24
  • 39
5
votes
2 answers

how to create savedInstanceState for dynamically selected image in Android?

I create a android application.Select image from gallery using a button and retrieve in the ImageView. The image fetching is successful. Now I want to saved the state of the selected Image.I try to fix.It makes crash application.When I change the…
reegan29
  • 920
  • 1
  • 12
  • 30
4
votes
2 answers

savedInstanceState is null after first app shutdown but not after second

I am following this codelab Android Kotlin Fundamentals 04.2: Complex lifecycle situations https://codelabs.developers.google.com/codelabs/kotlin-android-training-complex-lifecycle/index.html#4 In tast 5 you simulate app shutdown and use…
4
votes
0 answers

Android: Previous activity flashes white when changing theme with setDefaultNightMode() (Device Specific)

I am working on an app that has a main activity and a settings activity where the user can manually change the theme to dark mode. I implemented and tested this setting change on my Samsung S8 device and it worked fine. However, I then tested it on…
1
2 3
13 14