Skip to content

Commit 775bcac

Browse files
committed
Updating the documentation of share action provider.
1. Added some clarification how a developer can use the same provide with different historical files in a context dependent manner. Change-Id: I2a3390ade7e4b8b1170d381668e1439e52c17b7e
1 parent 6e24d0c commit 775bcac

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

core/java/android/widget/ShareActionProvider.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,25 @@ public void onPrepareSubMenu(SubMenu subMenu) {
240240
* <p>
241241
* <strong>Note:</strong> The history file name can be set any time, however
242242
* only the action views created by {@link #onCreateActionView()} after setting
243-
* the file name will be backed by the provided file. Hence, if you are using
244-
* a share action provider on a menu item and want to change the history file
245-
* based on the type of the currently selected item, you need to call
246-
* {@link android.app.Activity#invalidateOptionsMenu()} to force the system
247-
* to recreate the menu UI.
243+
* the file name will be backed by the provided file. Therefore, if you want to
244+
* use different history files for sharing specific types of content, every time
245+
* you change the history file {@link #setShareHistoryFileName(String)} you must
246+
* call {@link android.app.Activity#invalidateOptionsMenu()} to recreate the
247+
* action view. You should <strong>not</strong> call
248+
* {@link android.app.Activity#invalidateOptionsMenu()} from
249+
* {@link android.app.Activity#onCreateOptionsMenu(Menu)}.
248250
* <p>
251+
* <code>
252+
* private void doShare(Intent intent) {
253+
* if (IMAGE.equals(intent.getMimeType())) {
254+
* mShareActionProvider.setHistoryFileName(SHARE_IMAGE_HISTORY_FILE_NAME);
255+
* } else if (TEXT.equals(intent.getMimeType())) {
256+
* mShareActionProvider.setHistoryFileName(SHARE_TEXT_HISTORY_FILE_NAME);
257+
* }
258+
* mShareActionProvider.setIntent(intent);
259+
* invalidateOptionsMenu();
260+
* }
261+
* <code>
249262
*
250263
* @param shareHistoryFile The share history file name.
251264
*/

0 commit comments

Comments
 (0)