From de0c99e89bfe2df43e363f2521c55d5da166ddad Mon Sep 17 00:00:00 2001 From: Andrew Solovay Date: Mon, 12 May 2014 19:50:37 -0700 Subject: [PATCH 1/2] Noted that OnSharedPreferenceChangeListener does not store a strong reference to the listener. Because of this, the listener is susceptible to garbage collection unless the caller preserves a strong reference to it. We suggest that the caller store a reference to the listener in an instance field of an object that will exist as long as the listener is needed. Also fixed code sample formatting in Settings.jd (some lines were overlong). Docs are staged in: http://asolovay.mtv:8901/guide/topics/ui/settings.html#Listening http://asolovay.mtv:8901/reference/android/content/SharedPreferences.html#registerOnSharedPreferenceChangeListener(android.content.SharedPreferences.OnSharedPreferenceChangeListener) Bug: 10437648 Change-Id: I48f5b87fa2ca7a240661d0cc00114d225819d54d --- .../android/content/SharedPreferences.java | 9 +++- docs/html/guide/topics/ui/settings.jd | 42 +++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/core/java/android/content/SharedPreferences.java b/core/java/android/content/SharedPreferences.java index d4f7f06b008d1..00c2d8f78055e 100644 --- a/core/java/android/content/SharedPreferences.java +++ b/core/java/android/content/SharedPreferences.java @@ -355,7 +355,14 @@ public interface SharedPreferences { /** * Registers a callback to be invoked when a change happens to a preference. - * + * + *

Caution: The preference manager does + * not currently store a strong reference to the listener. You must store a + * strong reference to the listener, or it will be susceptible to garbage + * collection. We recommend you keep a reference to the listener in the + * instance data of an object that will exist as long as you need the + * listener.

+ * * @param listener The callback that will run. * @see #unregisterOnSharedPreferenceChangeListener */ diff --git a/docs/html/guide/topics/ui/settings.jd b/docs/html/guide/topics/ui/settings.jd index d96447dc032f8..30b7eecc785fb 100644 --- a/docs/html/guide/topics/ui/settings.jd +++ b/docs/html/guide/topics/ui/settings.jd @@ -820,7 +820,8 @@ public class SettingsActivity extends PreferenceActivity public static final String KEY_PREF_SYNC_CONN = "pref_syncConnectionType"; ... - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, + String key) { if (key.equals(KEY_PREF_SYNC_CONN)) { Preference connectionPref = findPreference(key); // Set summary to be the user-description for the selected value @@ -863,7 +864,40 @@ protected void onPause() { } +

Caution: When you call {@link +android.content.SharedPreferences#registerOnSharedPreferenceChangeListener +registerOnSharedPreferenceChangeListener()}, the preference manager does not +currently store a strong reference to the listener. You must store a strong +reference to the listener, or it will be susceptible to garbage collection. We +recommend you keep a reference to the listener in the instance data of an object +that will exist as long as you need the listener.

+

For example, in the following code, the caller does not keep a reference to +the listener. As a result, the listener will be subject to garbage collection, +and it will fail at some indeterminate time in the future:

+ +
+prefs.registerOnSharedPreferenceChangeListener(
+  // Bad! The listener is subject to garbage collection!
+  new SharedPreferences.OnSharedPreferenceChangeListener() {
+  public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
+    // listener implementation
+  }
+});
+
+ +

Instead, store a reference to the listener in an instance data field of an +object that will exist as long as the listener is needed:

+ +
+SharedPreferences.OnSharedPreferenceChangeListener listener =
+    new SharedPreferences.OnSharedPreferenceChangeListener() {
+  public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
+    // listener implementation
+  }
+};
+prefs.registerOnSharedPreferenceChangeListener(listener);
+

Managing Network Usage

@@ -1142,13 +1176,15 @@ protected Parcelable onSaveInstanceState() { final Parcelable superState = super.onSaveInstanceState(); // Check whether this Preference is persistent (continually saved) if (isPersistent()) { - // No need to save instance state since it's persistent, use superclass state + // No need to save instance state since it's persistent, + // use superclass state return superState; } // Create instance of custom BaseSavedState final SavedState myState = new SavedState(superState); - // Set the state's value with the class member that holds current setting value + // Set the state's value with the class member that holds current + // setting value myState.value = mNewValue; return myState; } From 9562863cf184fe99be223aff9700b3ceb8559e1a Mon Sep 17 00:00:00 2001 From: Andrew Solovay Date: Mon, 19 May 2014 16:45:19 -0700 Subject: [PATCH 2/2] doc: Updated branding guidelines per request from @deniseamling. Per her team's request, I also removed the AI version of the Google Play Store icon, and replaced it with a high-rez PNG version. Current version of doc is staged at: http://asolovay.mtv:9010/distribute/tools/promote/brand.html (Denise gave me a LGTM via email.) Bug: 14621461 Change-Id: Id44a0dc73c7ef2f2bde595a1e98b75083d126176 --- docs/html/distribute/tools/promote/brand.jd | 76 +- .../images/brand/Google_Play_Store_600.png | Bin 0 -> 124868 bytes docs/image_sources/brand/Google_Play_Store.ai | 1419 ----------------- 3 files changed, 36 insertions(+), 1459 deletions(-) create mode 100644 docs/html/images/brand/Google_Play_Store_600.png delete mode 100644 docs/image_sources/brand/Google_Play_Store.ai diff --git a/docs/html/distribute/tools/promote/brand.jd b/docs/html/distribute/tools/promote/brand.jd index 2116c0f10f781..9b9f9a3ef495f 100644 --- a/docs/html/distribute/tools/promote/brand.jd +++ b/docs/html/distribute/tools/promote/brand.jd @@ -9,6 +9,11 @@ page.tags="brand, bugdroid, assets" promotional materials. You can use the icons and other assets on this page provided that you follow the guidelines.

+

Use of the Android or Google Play brands must be reviewed by the Android +Partner Marketing team. Use the Android and Google Play Brand Permissions Inquiry form to submit your +marketing for review.

+

Android

The following are guidelines for the Android brand @@ -29,10 +34,12 @@ provided that you follow the guidelines.

  • Incorrect: "Android MediaPlayer"
  • Correct: "MediaPlayer for Android"
  • -

    If used with your logo, "for Android" needs to be smaller in size than your logo. +

    If used with your logo, "for Android" should be no larger than 90% of your logo’s size. First instance of this use should be followed by a TM symbol, "for Android™".

    -
  • Android may be used as a descriptor, as long as it is followed by a proper generic term. +
  • Android may be used as a descriptor, as long as it is followed by a + proper generic term. (Think of "Android" as a term used in place of + "the Android platform.")