Questions tagged [onsaveinstancestate]

230 questions
2
votes
1 answer

How to store recyclerview data , while changing view (Fragments) via Bottom Navigation?

I am following this question how to store recyclerview data on onSaveInstanceState I also found How to save state of view class? and Fragment save view state. Context I give data in form of DataModel (implements Parcelable) to recyclerview in one of…
2
votes
1 answer

How to record a user action and replay when he returns back?

I wants to know is there a way to save the user action done in app and replay them when he returns back. Let me explain that clearly. Like in my app I provided a lot of free PDFs to users. But to download them the user should make a login. But I…
2
votes
2 answers

kotlin, how to make a hashMap parcelable

Having a variable is hashMap, and need to put in bundle as parcelable to be saved and restored in onSaveStateInstance()/onCreateView() : val map: HashMap? = hashMapOf(IntRange(0, 4) to "x", IntRange(5, -1) to…
lannyf
  • 9,865
  • 12
  • 70
  • 152
2
votes
3 answers

Restore CountDownTimer object after rotation

When i rotate, onCreate method is called so i lose all of my vars , that's why i want to restore CountDownTimer object . The onTick and onFinish callback methods of CDT object are active as the countdownTimer keep running. I think the solution is to…
2
votes
2 answers

How to save fragments states to avoid re-creating them

I've implemented something like the below picture: I have some Tabs and every tab may have some buttons which load some different fragments. In this situation, in Tab 1, Button 1 loads Fragment 1, and Button 2 loads Fragment 2 and each time the…
2
votes
1 answer

Fragment's onCreate is being called before transaction.commit

I have multiple fragments in viewpager. Fragment A, Fragment B , Fragment C and Fragment D. Fragment C is replacing itself with another fragment which extends list fragment. I want to replace the fragment when only Fragment C is visible. because…
user10611404
2
votes
3 answers

Retain data in Fragment switching

Working on an app that included 3 fragments. I want to retain data in the FragmentA when the user decides to switch back to FragmentA from FragmentB or FragmentC via BottomNavigationView. My code works great with changing screen orientation, but for…
Miha M
  • 379
  • 1
  • 3
  • 14
2
votes
1 answer

onSaveInstanceState() not being called when user presses home button

I ran into a frustrating issue while trying to preserve state through onSaveInstanceState() so I figured to offer up my scenario and answer my own question in order to help others. (The code is in Kotlin, but the concepts are the same) I have…
The4thIceman
  • 3,709
  • 2
  • 29
  • 36
2
votes
1 answer

App crashes after tapping the home button and then returning to the same activity by clicking the app icon

When I launch my activity after having installed it, it runs fine; then if I tap the home button of the device (I'm using Lenovo TB3 tablet), and then launch the activity again by clicking on its icon, the app crashes and relaunch itself…
2
votes
3 answers

commit() fragment transaction after activity.onSaveInstanceState() has been called

In my application I have an Activity that holds 3 Fragments. The very first time the Activity is created, Fragment 1 is displayed. Next, all fragment transactions will be executed after a network operation. For example: Fragment 1 has a button to…
2
votes
1 answer

Casting to ArrayList when saving List in onSaveInstanceState

I coulnd't find an answer on that: I want to save a Parcelable ArrayList in onSaveInstanceState, but it does not accept an ArrayList that is declared as a List when I do it like this: outState.putParcelableArrayList(KEY_QUESTION_LIST,…
Florian Walther
  • 6,237
  • 5
  • 46
  • 104
2
votes
1 answer

Keep the CountDownTimer running after orientation change

I have made a CountDownTimer that works perfectly - you can get the correct time for soft/medium/hard-boiling an egg. My problem is that the timer resets after orientation change. I have googled and tried so many solution, still I don't understand…
2
votes
2 answers

Restoring State of Spinners and Their Adapters

I am having issues trying to restore state of Android Spinners in my application. Currently there are multiple Spinners in my Activity's ListView header that depend on one another, as the selection of one Spinner loads data for the subsequent…
2
votes
2 answers

What happens to the Activity lifecycle after an app update?

Suppose this scenario. You have an app where you fill a form in one activity. The activity uses onRestoreInstanceState and onSaveInstanceState to save the responses of the form. If a user is filling the form with app version 1, and then the…
2
votes
1 answer

finish() vs startActivity()

According to Android documentation, finish() does exactly what the "back" button does. So basically onStop() is called when I call finish(). I tried to override onStateSaveInstance() to save the current state, but it is never called. However, if I…
Florin
  • 43
  • 4
1 2
3
15 16