onrestoreinstancestate

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;

Should I restore savedinstancestate in onCreate or in onRestoreInstanceState?

天大地大妈咪最大 提交于 2020-01-23 04:26:28
问题 I have an activity that starts some other activities for results, so when the result comes back, the activity may or may not have been destroyed and recreated. I have overridden onSaveInstanceState so as to add the data that needs to be preserved and restored. When the activity gets destroyed and recreated, onCreate is passed the savedInstanceState bundle; but also onRestoreInstanceState() is called and passed the same bundle. So where should I put the code that extracts the data from the

Image on ImageView lost after Activity is destroyed

橙三吉。 提交于 2019-12-29 08:12:25
问题 I am trying to make an app where I can let a user select a picture to display on their profile. I am able to browse and set their selected image on imageview. But the image is lost once the the activity is destroyed. I tried to implement onSaveInstanceState but still it's the same. I'm wondering if I am using it correctly. I hope you can help a newbie like me. Thanks in advance. Here's the code that I'm using: public class AccountFragment extends Fragment implements OnClickListener { private

Image on ImageView lost after Activity is destroyed

匆匆过客 提交于 2019-12-29 08:12:15
问题 I am trying to make an app where I can let a user select a picture to display on their profile. I am able to browse and set their selected image on imageview. But the image is lost once the the activity is destroyed. I tried to implement onSaveInstanceState but still it's the same. I'm wondering if I am using it correctly. I hope you can help a newbie like me. Thanks in advance. Here's the code that I'm using: public class AccountFragment extends Fragment implements OnClickListener { private

Issue with use of onSaveInstanceState and onRestoreInstanceState

扶醉桌前 提交于 2019-12-25 04:52:38
问题 Im using the below code in my shopping cart activity. when i added the items to cart, it shows the items in the cart. but when i open another activity and go back to the cart it shows null. then i found use of onSaveInstanceState and onRestoreInstanceState .. even after i use this code it shows null. can anyone point out what have gone wrong in this code. what im expecting by use of this code is when i added the items to cart it will save in onSaveInstanceState, and when i open the cart again

Android openFileChooser onCreate() called after onActivityResult()

╄→尐↘猪︶ㄣ 提交于 2019-12-12 04:50:03
问题 I have a webview and on one of the pages there is an Upload Photo button. I found some code to implement the file chooser (Android, why so hard????) and if I pick the gallery everything works fine. If I choose camera 1 of 10 times it works. But most of the time when I take the picture and click save (this is all in the camera activity) the webview loads the first page loaded when the app was started. It seems that the onActivityResult() is not called but instead of it onCreate() is and this

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());

Should I restore savedinstancestate in onCreate or in onRestoreInstanceState?

牧云@^-^@ 提交于 2019-12-04 23:03:13
I have an activity that starts some other activities for results, so when the result comes back, the activity may or may not have been destroyed and recreated. I have overridden onSaveInstanceState so as to add the data that needs to be preserved and restored. When the activity gets destroyed and recreated, onCreate is passed the savedInstanceState bundle; but also onRestoreInstanceState() is called and passed the same bundle. So where should I put the code that extracts the data from the bundle and restores the state? In onCreate or in onRestoreInstanceState? Is the latter guaranteed to be

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(