Questions tagged [android-savedstate]

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

197 questions
4
votes
2 answers

SavedStateHandleController.attachToLifecycle : Already attached to lifecycleOwner

I am using AbstractSavedStateViewModelFactory to use SavedStateHandle in a View Model with non-empty constructor. But I get an Illegal State Exception saying it is already attached to a life-cycle owner(see below). When I use…
ashwin mahajan
  • 1,654
  • 5
  • 27
  • 50
4
votes
1 answer

Cases when savedInstanceState is NOT null

If I do not explicitly call onSaveInstanceState(), which are possibilities, when savedInstanceState is not null in onCreate? I see one option, when system recreates my app after crash - then savedInstanceState is not null. Which are other options?
4
votes
0 answers

Saving RecyclerView Scroll position

I have an activity with a ViewPager and 3 fragments called A,B,C. A has a recyclerView populated by cardView and each card implements and OnClickListener which leads to a new Activity D. I want to be able to save the recyclerView scroll position…
4
votes
2 answers

Unable to resume activity after taking a picture with camera

i'm trying to make an activity where i can upload an image into an imageView by using camera or gallery. On my tablet it works fine but on my galaxy s4 i can't restore activity after taking the picture with the camera. Here's the…
4
votes
2 answers

Android - Navigation Up from Activity to Fragment

I'm developing some application and I have one problem. I have : 1. Activity A (Navigation Drawer pattern) with ListFragment in FrameLayout: xml:
4
votes
2 answers

Put HashMap> in savedInstanceState

I have a problem with adding values in savedInstanceState in Android. I tried to find solution on the internet, but I cannot seem to find a solution. Maybe some of you might know where the problem is. I need to put HashMap> to savedInstanceState,…
marko kurt
  • 205
  • 4
  • 12
3
votes
3 answers

SavedStateHandle does not persist data

I followed the instructions in the following page and created a viewModel, but SavedStateHandle does not work when I close the app and open it again. Here is the page: Saved State module for ViewModel Here is my view model class: class…
a.toraby
  • 3,232
  • 5
  • 41
  • 73
3
votes
1 answer

Android:SaveState, Fragments and ViewModel: what am I doing wrong?

I have the single activity with several fragments on top, as Google recommends. In one fragment I wish to place a switch, and I wish to still know it's state when I come back from other fragments. Example: I am in fragment one, then I turn on the…
3
votes
1 answer

Saved Game + Real Time Multiplayer Android

I want to build a game that has realTimeMultiplayer and support for saved game. Both functionalities come from the Play Services API provided by android. The players would invite their friends, play in real-Time, then whenever one player quits, the…
3
votes
1 answer

MVP in Android app - Presenter state

I work with map in Android. So, I want to save state of some of my presenters to save data, when I leaved activity(not when rotate the screen). I can't find the solution besides singleton with ArrayList, but I would like to use already written…
3
votes
1 answer

Android doesn't automatically save view states

Basically, I have a TextView and two EditText views in one activity. From that activity, a different activity is started. If I press the hardware back button on the device (ending the second activity), the views' states are the same as before, which…
Elliot Alderson
  • 546
  • 2
  • 17
3
votes
1 answer

Difference between Saved Instance State and Static variables

I'm creating an app that downloads some stuff when it starts and show a list to the user, but i don't want it re-downloading the list every time the app opens, or whenever the user changes to a different activity and comes back. To solve this, i'm…
George
  • 6,886
  • 3
  • 44
  • 56
3
votes
2 answers

What happens to the code when someone closes or kills an app?

I have been looking into storing data for my app and trying to choose between different methods (onSaveInstanceState, onPause/onResume) and different methods of storing(states in onSaveInstanceState, SQLite, Prefences). I am curious what happens to…
John Targaryen
  • 1,109
  • 1
  • 13
  • 29
3
votes
0 answers

Can Instance State be Persisted Across an App Update?

Is it possible for an Android app's savedInstanceState to be persisted across an app update? Take the following situation for example: I have a Parcelable model that gets written in onSaveInstanceState App updates, the structure of that…
Tspoon
  • 3,670
  • 1
  • 26
  • 33
2
votes
1 answer

What is difference between SavedStateHandle and rememberSaveable?

As far as I know, with Android Compose, SavedStateHandle is used with ViewModel and follows the ViewModel lifecycle and key-value map and it can be used as flow. rememberSaveable is used with variables in Composable and follows the Composable…
1
2
3
13 14