Rework activity lifecycle so onSaveInstanceState() is after onPause().
The goal is to fix a bunch of fragment-related bugs caused by various
things trying to do fragment transactions after onPause()... which
currently throws an exception, since this is after the activity's state
has been saved so the new fragment state can be lost.
The basic change is relatively simple -- we now consider processes
hosting paused or stopping activities to be unkillable, and the client
code now does the onSaveInstanceState() as part of stopping the
activity.
For compatibility, if an app's targetSdkVersion is < HONEYCOMB, the
client side will still call onSaveInstanceState() prior to onPause()
and just hold on to that state until it needs to report it in once
being stopped.
Also included here is a change to generate thumbnails by taking
screenshots. The code for generating thumbnails by re-rendering
the view hierarchy is thus removed.
Change-Id: Iac1191646bd3cadbfe65779297795f22edf7e74a
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index a0a6b42..d679ef6 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -297,7 +297,7 @@
* <p>Followed by either <code>onResume()</code> if the activity
* returns back to the front, or <code>onStop()</code> if it becomes
* invisible to the user.</td>
- * <td align="center"><font color="#800000"><strong>Yes</strong></font></td>
+ * <td align="center"><font color="#800000"><strong>Pre-{@link android.os.Build.VERSION_CODES#HONEYCOMB}</strong></font></td>
* <td align="center"><code>onResume()</code> or<br>
* <code>onStop()</code></td>
* </tr>
@@ -347,6 +347,14 @@
* because the later is not part of the lifecycle callbacks, so will not
* be called in every situation as described in its documentation.</p>
*
+ * <p class="note">Be aware that these semantics will change slightly between
+ * applications targeting platforms starting with {@link android.os.Build.VERSION_CODES#HONEYCOMB}
+ * vs. those targeting prior platforms. Starting with Honeycomb, an application
+ * is not in the killable state until its {@link #onStop} has returned. This
+ * impacts when {@link #onSaveInstanceState(Bundle)} may be called (it may be
+ * safely called after {@link #onPause()} and allows and application to safely
+ * wait until {@link #onStop()} to save persistent state.</p>
+ *
* <p>For those methods that are not marked as being killable, the activity's
* process will not be killed by the system starting from the time the method
* is called and continuing after it returns. Thus an activity is in the killable
@@ -489,7 +497,7 @@
* paused. Note this implies
* that the user pressing BACK from your activity does <em>not</em>
* mean "cancel" -- it means to leave the activity with its current contents
- * saved away. Cancelling edits in an activity must be provided through
+ * saved away. Canceling edits in an activity must be provided through
* some other mechanism, such as an explicit "revert" or "undo" option.</p>
*
* <p>See the {@linkplain android.content.ContentProvider content package} for
@@ -1255,11 +1263,8 @@
* can use the given <var>canvas</var>, which is configured to draw into the
* bitmap, for rendering if desired.
*
- * <p>The default implementation renders the Screen's current view
- * hierarchy into the canvas to generate a thumbnail.
- *
- * <p>If you return false, the bitmap will be filled with a default
- * thumbnail.
+ * <p>The default implementation returns fails and does not draw a thumbnail;
+ * this will result in the platform creating its own thumbnail if needed.
*
* @param outBitmap The bitmap to contain the thumbnail.
* @param canvas Can be used to render into the bitmap.
@@ -1272,40 +1277,7 @@
* @see #onPause
*/
public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) {
- if (mDecor == null) {
- return false;
- }
-
- int paddingLeft = 0;
- int paddingRight = 0;
- int paddingTop = 0;
- int paddingBottom = 0;
-
- // Find System window and use padding so we ignore space reserved for decorations
- // like the status bar and such.
- final FrameLayout top = (FrameLayout) mDecor;
- for (int i = 0; i < top.getChildCount(); i++) {
- View child = top.getChildAt(i);
- if (child.isFitsSystemWindowsFlagSet()) {
- paddingLeft = child.getPaddingLeft();
- paddingRight = child.getPaddingRight();
- paddingTop = child.getPaddingTop();
- paddingBottom = child.getPaddingBottom();
- break;
- }
- }
-
- final int visibleWidth = mDecor.getWidth() - paddingLeft - paddingRight;
- final int visibleHeight = mDecor.getHeight() - paddingTop - paddingBottom;
-
- canvas.save();
- canvas.scale( (float) outBitmap.getWidth() / visibleWidth,
- (float) outBitmap.getHeight() / visibleHeight);
- canvas.translate(-paddingLeft, -paddingTop);
- mDecor.draw(canvas);
- canvas.restore();
-
- return true;
+ return false;
}
/**