android-savedstate

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

纵饮孤独 提交于 2021-01-28 09:11:51
问题 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 { TestListAdapter() } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { return inflater.inflate(R.layout.fragment_test, container, false) } override fun onViewCreated(view: View,

How to lazily save ViewModel's SavedStateHandle?

大城市里の小女人 提交于 2021-01-27 23:31:03
问题 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 data through system-initiated process death, which SavedStateHandle is designed for. But I don't want to persist this data in a database because it is only relevant to the current user experience. I have integrated my ViewModels with Hilt and received

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

萝らか妹 提交于 2020-04-30 04:31:05
问题 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<String> liveData; if (defaultValue != null) { liveData = savedStateHandle.get(KEY, defaultValue); } else { liveData = savedStateHandle.get(KEY); } However, I notice that when tried to compile the code, the statement below is not compilable. savedStateHandle.get(KEY, defaultValue); It

Retain EditText with Screen Rotation using Databinding Library

徘徊边缘 提交于 2020-04-05 06:51:07
问题 I have two classes AdminPinActivity.kt and AdminPinActivityPresenter.kt AdminPinActivity.kt: class AdminPinActivity : InjectableAppCompatActivity() { @Inject lateinit var adminPinActivityPresenter: AdminPinActivityPresenter private var input_Pin: String = "" private var input_Confirm_Pin: String = "" companion object { fun createAdminPinActivityIntent(context: Context, profileId: Int, colorRgb: Int): Intent { val intent = Intent(context, AdminPinActivity::class.java) intent.addFlags(Intent

How to save the fields data while changing the Layout on screen rotation

纵饮孤独 提交于 2019-12-24 18:08:03
问题 I have read a lot of things about the data save instance and restore but Unable to implement in my case. What is my case in application . I am using the Activity (MainActivity) and calling the fragment in it let say ParentFragment ParentFragment Calls the ChildFragment in it though ParentFragment has its own views such as TextViews which takes First name, Last name and age and below this part I am programatically calling the ChildFragment So in this way I have 2 fragments in the MainActivity,

How do I store users position from RecyclerView and use ScrollToPosition() to cast it?

让人想犯罪 __ 提交于 2019-12-13 04:17:43
问题 I am using a RecyclerView to display movie posters in a Gridlayout. My goal is to save the position of the user, so when they rotate the phone it will save their position. movieGrid.scrollToPosition(10); That line of code has been the only line of code that works to go to a position other than the top when the phone rotates. I have tried layoutManager.scrollToPositionWithOffset(position[0], position[1]); But it didnt work. This is the complete code for my MainActivity.java public class

How do I retrieve the previous fragment upon opening an app from background? (app that wasn't killed)

邮差的信 提交于 2019-12-13 01:42:53
问题 I have a pretty unique issue where I am trying to retrieve previous fragment that was there before I went to the homescreen via the current fragment( last visible fragment) Not to confuse any further, here's the steps to repro my issue 1 ) launch the mainactivity, from there open fragment A via a button click (say button A) 2) from fragment A , press another button ,say B, which will open fragment B. 3) Fragment B has a close and save button , pressing which leads me back to the previous

Make uploaded image remain after layout/Activity change

淺唱寂寞╮ 提交于 2019-12-12 01:49:23
问题 I am still a rookie in terms of java and android programming, I believe I have come far in the last weeks but now I'm a little bit stuck and I would really appreciate your help. I am trying to develop an app that can create a User profile Layout. So far I have it ready, drawing the user's data from a web service. But now I have to add a way for the user to upload his photo from gallery or camera. So far I have achieved this with the next code: public void loadimage (View view) { Intent intent

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

混江龙づ霸主 提交于 2019-12-04 22:26:46
问题 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 property... I see from some tests but I can't find anything about this in the documentation. How can I know what is saved/restored implicitly, without my intervention? For example, where I can find that the EditText.Text is automatically saved