首先来介绍onSaveInstanceState() 和 onRestoreInstanceState() .关于这两个方法,一些朋友可能在Android开发过程中很少用到,但在有时候掌握其用法会帮我们起到比较好的效果.尤其是在应用程序在不知道的情况下退出后,如何实现其数据保存的功能.先来让我们看下这两个方法的有什么样的作用. 1. 基本作用:  Activity的 onSaveInstanceState() 和 onRestoreInstanceState()并不是生命周期方法,它们不同于 o…
1. 基本作用: Activity的 onSaveInstanceState() 和 onRestoreInstanceState()并不是生命周期方法,它们不同于 onCreate().onPause()等生命周期方法,它们并不一定会被触发.当应用遇到意外情况(如:内存不足.用户直接按Home键)由系统销毁一个Activity时,onSaveInstanceState() 会被调用. 但是当用户主动去销毁一个Activity时,例如在应用中按返回键,onSaveInstanceState()就…
Android Activity的onSaveInstanceState() 和 onRestoreInstanceState()方法: 1. 基本作用: Activity的 onSaveInstanceState() 和 onRestoreInstanceState()并不是生命周期方法,它们不同于 onCreate().onPause()等生命周期方法,它们并不一定会被触发.当应用遇到意外情况(如:内存不足.用户直接按Home键)由系统销毁一个Activity时,onSaveInstance…
先看Application Fundamentals上的一段话:    Android calls onSaveInstanceState() before the activity becomes vulnerable to being destroyed by the system, but does not bother calling it when the instance is actually being destroyed by a user action (such as pr…
当某个activity变得“容易”被系统销毁时,该activity的onSaveInstanceState就会被执行,除非该activity是被用户主动销毁的,例如当用户按BACK键的时候. 注意上面的双引号,何为“容易”?言下之意就是该activity还没有被销毁,而仅仅是一种可能性.这种可能性有哪些?通过重写一个activity的所有生命周期的onXXX方法,包括onSaveInstanceState和onRestoreInstanceState方法,我们可以清楚地知道当某个activity…
为什么要介绍这2个方法呢?这是因为在我们的开发中最近遇到了一个很诡异的bug.大体是这样的:在我们的ViewPager中 有2页的root view都是ScrollView,我们在xml里面都用了android:id="@+id/scroll_view"这样的代码,即2个布局里面的 ScrollView用了同一个id.我们重载了ScrollView的onSaveInstanceState()用来save当前的scrollX和scrollY,在使用过程中 发现restore回来的时候其中…
本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceState(),并且在介绍这两个方法之后,再分别来实现使用InstanceState保存和恢复数据功能.Android实现屏幕旋转异步下载效果这样两个示例.   首先来介绍onSaveInstanceState() 和 onRestoreInstanceState() .关于这两个方法,一些朋友可能在Android开发过程中很少用到,但在有时候掌握其用法会…
本文摘自: http://h529820165.iteye.com/blog/1399023 Android calls onSaveInstanceState() before the activity becomes vulnerable to being destroyed by the system, but does not bother calling it when the instance is actually being destroyed by a user action…
先看Application Fundamentals上的一段话:    Android calls onSaveInstanceState() before the activity becomes vulnerable to being destroyed by the system, but does not bother calling it when the instance is actually being destroyed by a user action (such as pr…
之所以有这个话题,是因为工作遇到过两个问题.一个问题是页面空白,fragment重复创建.另一个问题是登录页用到了AutoCompleteTextView,调用showDropDown()方法导致crash. 1. onSaveInstanceState() 和 onRestoreInstanceState()并不配对 2.触发时机 onSaveInstanceState()(1).当用户按下HOME键时.(2).长按HOME键,选择运行其他的程序时. (3).按下电源按键(关闭屏幕显示)时.(…