onsaveinstancestate

how to store recyclerview data on onSaveInstanceState

拥有回忆 提交于 2021-02-16 18:21:06
问题 I want to save data from the API in the RecyclerView so that when rotating the screen is not reloaded I think I can use onSaveInstanceState but still don't really understand how to use it @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final RecyclerView rvTVShow = view.findViewById(R.id.rv_shows); rvTVShow.setHasFixedSize(true); rvTVShow.setLayoutManager(new LinearLayoutManager(getActivity()));

Fragment save view state

大兔子大兔子 提交于 2021-02-10 19:56:26
问题 I have some Fragment with this structure: <RelativeLayout android:id="@+id/control_panel" android:visibility="gone"> <RelativeLayout android:id="@+id/control_panel_icon"> <ImageView android:id="@+id/control_panel_icon_1" android:src="@drawable/ic_control_panel_icon_1" /> <ImageView android:id="@+id/control_panel_icon_2" android:src="@drawable/ic_control_panel_icon_2" android:visibility="gone"/> </RelativeLayout> <TextView android:id="@+id/control_panel_tv" android:text="@string/not_available"

Keep the CountDownTimer running after orientation change

我是研究僧i 提交于 2021-02-10 12:07:51
问题 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 how to use the onSave and onRestore properly. Here's my code: Any tips? package com.dohman.boilaneggbae; import android.graphics.PorterDuff; import android.os.CountDownTimer; import android.support.v7.app.AppCompatActivity; import android.os.Bundle;

How to put serialize and get serializeContext in Kotlin Android?

巧了我就是萌 提交于 2020-02-08 10:06:33
问题 I want save and keep my state in fragment because when tap on recyclerView items and back to fragment with listener i lost my Context and my context in fragment is null . So i try to keep my context like this: override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) outState.putSerializable("SaveContext", context) } 回答1: You should initialize your context correctly. Check below as for example class MyFragment: Fragment() { private var mContext: Context? = null

Android java.lang.IllegalStateException in onRequestPermissionsResult()

好久不见. 提交于 2020-01-14 13:50:55
问题 I am working with sd card and so trying to get permission in runtime. Here is the code: public class MainActivity extends AppCompatActivity implements FileListFragment.OnFragmentInteractionListener { private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 111; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL

How to examine the size of the Bundle object in onSaveInstanceState?

三世轮回 提交于 2019-12-24 05:56:56
问题 I am using Android Studio 3.0.1 which allows to inspect the Bundle object in onSaveInstanceState : @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); } To do so add a breakpoint and once the debugger stops right click the Bundle object as shown in the screenshot and select "Show Bundle Objects..." from the context menu. Then a window opens to list the Bundle objects as shown in this screenshot: Is there a way to find out how much memory the

LayoutManager.onSaveInstanceState() not working

∥☆過路亽.° 提交于 2019-12-23 04:55:09
问题 I'm trying to save state of my RecyclerView with GridLayoutManager , but when calling onSaveInstanceState() of activity and when I try to call onSaveInstanceState() on layout manager that always return the same object. I trying use method " findFirstVisibleItemPosition ", but it always return -1. RecyclerView has adapter, adapter has some amount of elements, I can scroll them! I don't know why I can't get item position of fully initialized and working component ! Please help! There is my code

Can not perform this action after onSaveInstanceState Android

大憨熊 提交于 2019-12-11 14:07:52
问题 I am getting java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState . When I did fragmentManager.popBackStack(). This crash is random . I am not overriding onSaveInstanceState() in my activity. Navigator.post(new Runnable() { @Override public void run() { if (actRef != null && actRef.get() != null) { if (isLastFragment()) { finish(); } else { if (fragMngr != null) { try { fragMngr.popBackStack();//crashing in this line /** * check if it is last fragment */ if