onsaveinstancestate

Android how to save realm results with onSaveInstanceState for screen rotation

时间秒杀一切 提交于 2019-12-11 06:36:46
问题 My problem is this: When i open dialog fragment, i send realm and realm results from activity to dialog fragment. I always send different realm results to dialog fragment, depending what i click in activity. This is code in dialog fragment where i receive realm and realmResults from activity, when i click to open dialog fragment: public void setChangeNoteListener(ChangeNoteListener mChangeNoteListener, RealmResults<Drop> realmResults, Realm realm) { mNotelistener = mChangeNoteListener;

Failure delivering result ResultInfo | java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

China☆狼群 提交于 2019-12-10 10:28:20
问题 I have Simple app first I display MainActivity then after MainActivity became visible I display TransparentActivity after that onClick I kill TransparentActivity and I create and display dialog. During last step I get Error Error Failure delivering result ResultInfo{who=null, request=1234, result=-1, data=Intent { }} to activity {com.example.kylu.layout/com.example.kylu.layout.GuidePhotoAlbum}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState MainActivity

Custom image view looses state on Marshmallow

走远了吗. 提交于 2019-12-08 10:44:37
问题 I am using the PhotoView library in my Android project. The project contains the SaveStatePhotoView which is used to keep the state (zoom level, position) of the image view on configuration changes (rotation, ...). // SaveStatePhotoView.java @Override protected void onRestoreInstanceState(Parcelable state) { if (!(state instanceof SavedState)) { super.onRestoreInstanceState(state); return; } final SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState());

Restore fragment with two views having the same id

对着背影说爱祢 提交于 2019-12-07 02:59:25
问题 I have a complex layout to implement. It has 19 sections that can be displayed or not based on plenty of parameters previously entered by the user. In order to simplify the code and to not display unused sections, the layout is created dynamically. Everything is inside a fragment. The fragment has a LinearLayout used as a container and, when the fragment is created, I generate all the necessary sections. Each section is managed by its own local adapter which is in charge to inflate the layout

Android Fragment 常见问题及解决方案

∥☆過路亽.° 提交于 2019-12-04 18:18:16
Fragment(主要探讨的是support库中的Fragment) Fragment的主要意义就是提供与Activity绑定的生命周期回调 Fragment不一定要向Activity的视图层级中添加View. 当某个模块需要获得Activity的生命周期回调的时候,就可以考虑通过Fragment来实现. 例如: DialogFragment, 调用show方法来显示一个Dialog(这个一个子Window,并不在Activity的视图层级中),当旋屏时,DialogFragment利用onDestroyView回调来dismiss Dialog,然后Activity重建之后,DialogFragment利用onStart回调再显示Dialog 当然,我们也可以创建一个完全没有UI的Fragment,比如BackgroundWorkerFragment,在onResume的时候执行一个Task,在onPause的时候暂停一个Task Fragment 生命周期 Fragment的生命周期非常复杂,分为以下几种情况: 如果是通过XML中的 <fragment/> 标签实例化的,那么第一个收到的回调将是 onInflate 如果 setRetainInstance(true) ,那么当Activity重建时,Fragment的 onDestroy

Android Activity或进程重启时数据保存与恢复

无人久伴 提交于 2019-12-02 21:59:17
前言 onRestoreInstanceState用来在意外中断时恢复保存的数据,onSaveInstanceState在意外中断时保存数据。这2个方法的使用是有条件的,因此,我们需要明白这2个方法触发的条件。 一、onSaveInstanceState会被调用的条件 正确的触发方式 1. 只要Activity不finish,Activity进入后台(比如Home键、电源键、跳转到其他的Activity),则其就会调用onSaveInstanceState(Bundle outState)方法,而且这个方法是在onPause方法之间进行调用的。 2、屏幕旋转 错误的触发方式 1. 如果Activity是执行了finish方法,才进入的后台,则不调用这个onSaveInstanceState(Bundle outState),而且下次再进入时,也不会使用这个保存的数据。 2. 在系统杀掉Activity所在的进程时,onSaveInstanceState(Bundle outState)方法根本就没有调用过。 二、onRestoreInstanceState调用的条件 onSaveInstanceState被调用是为了保存数据,然而这并不意味着onRestoreInstanceState会被调用,那么,什么时候会被调用呢。 场景一: 当前ActivityA启动了ActivityB时‍

Android InstanceState详解

和自甴很熟 提交于 2019-12-02 19:35:54
一、onSaveInstanceState 1. 代码示例: 当屏幕的方向发生了改变, Activity会被摧毁并且被重新创建,如果你想在Activity被摧毁前缓存一些数据,并且在Activity被重新创建后恢复缓存的数据。可以重写Activity的 onSaveInstanceState() 和 onRestoreInstanceState()方法,如下代码所示: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(savedInstanceState != null){ boolean myBoolean = savedInstanceState.getBoolean("MyBoolean"); double myDouble = savedInstanceState.getDouble("myDouble"); String myString = savedInstanceState.getString("myString"); Log.i(

when is onRestoreInstanceState called?

独自空忆成欢 提交于 2019-11-27 07:46:40
Sorry for my incomprehension, but I am new in the android development. I have an application with activity A and activity B in it, and I go from activity A to activity B. When I left activity A, the onSaveInstanceState method was called, but when I went back to activity A (from activity B in the same application), the bundle in the onCreate method was null. What can I do, to save the activity A's previous state? I only want to store the data for the application lifetime. Can someone help me with this? Here is my code for Activity A: @Override protected void onCreate(Bundle savedInstanceState)

when is onRestoreInstanceState called?

三世轮回 提交于 2019-11-26 13:49:13
问题 Sorry for my incomprehension, but I am new in the android development. I have an application with activity A and activity B in it, and I go from activity A to activity B. When I left activity A, the onSaveInstanceState method was called, but when I went back to activity A (from activity B in the same application), the bundle in the onCreate method was null. What can I do, to save the activity A's previous state? I only want to store the data for the application lifetime. Can someone help me