下面列出了android.os.Bundle#EMPTY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testSaveState() {
repoInfoPresenter.onCreateView(null);
Bundle bundle = Bundle.EMPTY;
repoInfoPresenter.onSaveInstanceState(bundle);
repoInfoPresenter.onStop();
repoInfoPresenter.onCreateView(bundle);
verify(mockView, times(2)).showBranches(branchList);
verify(mockView, times(2)).showContributors(contributorList);
verify(model).getRepoContributors(TestConst.TEST_OWNER, TestConst.TEST_REPO);
verify(model).getRepoBranches(TestConst.TEST_OWNER, TestConst.TEST_REPO);
}
@TargetApi(Build.VERSION_CODES.O)
private Bundle getTransientBundle(JobParameters params) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return params.getTransientExtras();
} else {
return Bundle.EMPTY;
}
}
@Test
public void dispatchOnRestoreInstanceState() {
final Bundle bundle = Bundle.EMPTY;
dispatcher.onRestoreInstanceState(activity, bundle);
verify(lightCycleComponent1).onRestoreInstanceState(activity, bundle);
verify(lightCycleComponent2).onRestoreInstanceState(activity, bundle);
}
@Test
public void shouldNotifyOnSaveInstanceState() {
final Bundle bundle = Bundle.EMPTY;
dispatcher.onSaveInstanceState(fragment, bundle);
verify(lifeCycleComponent1).onSaveInstanceState(fragment, bundle);
verify(lifeCycleComponent2).onSaveInstanceState(fragment, bundle);
}
private static @Nullable String getSortClause(@Nullable Bundle queryArgs) {
queryArgs = queryArgs != null ? queryArgs : Bundle.EMPTY;
String sortClause = queryArgs.getString(ContentResolver.QUERY_ARG_SQL_SORT_ORDER);
if (sortClause == null && queryArgs.containsKey(ContentResolver.QUERY_ARG_SORT_COLUMNS)) {
sortClause = ContentResolver.createSqlSortClause(queryArgs);
}
return sortClause;
}
private void handleProviderApiEvent(Intent intent) {
int resultCode = intent.getIntExtra(BROADCAST_RESULT_CODE, RESULT_CANCELED);
Bundle resultData = intent.getParcelableExtra(BROADCAST_RESULT_KEY);
if (resultData == null) {
resultData = Bundle.EMPTY;
}
Provider provider;
switch (resultCode) {
case CORRECTLY_DOWNLOADED_EIP_SERVICE:
Log.d(TAG, "correctly updated service json");
provider = resultData.getParcelable(PROVIDER_KEY);
ProviderObservable.getInstance().updateProvider(provider);
PreferenceHelper.storeProviderInPreferences(preferences, provider);
if (EipStatus.getInstance().isDisconnected()) {
EipCommand.startVPN(context.getApplicationContext(), true);
}
break;
case CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE:
provider = resultData.getParcelable(PROVIDER_KEY);
ProviderObservable.getInstance().updateProvider(provider);
PreferenceHelper.storeProviderInPreferences(preferences, provider);
EipCommand.startVPN(context.getApplicationContext(), true);
break;
default:
break;
}
for (EipSetupListener listener : listeners) {
listener.handleProviderApiEvent(intent);
}
}
@Test
public void shouldNotifyOnCreate() {
final Bundle bundle = Bundle.EMPTY;
dispatcher.onCreate(fragment, bundle);
verify(lifeCycleComponent1).onCreate(fragment, bundle);
verify(lifeCycleComponent2).onCreate(fragment, bundle);
}
public FeedbackFragment(
CharSequence text,
@Nullable Set<Integer> earcons,
@Nullable Set<Integer> haptics,
@Nullable Bundle speechParams,
@Nullable Bundle nonSpeechParams) {
mText = new SpannableString(text);
mEarcons = new HashSet<>();
if (earcons != null) {
mEarcons.addAll(earcons);
}
mHaptics = new HashSet<>();
if (haptics != null) {
mHaptics.addAll(haptics);
}
mSpeechParams = new Bundle(Bundle.EMPTY);
if (speechParams != null) {
mSpeechParams.putAll(speechParams);
}
mNonSpeechParams = new Bundle(Bundle.EMPTY);
if (nonSpeechParams != null) {
mNonSpeechParams.putAll(nonSpeechParams);
}
}
@Override
public void setExtras(Bundle extras) {
mExtras = (extras == null) ? Bundle.EMPTY : extras;
}
@Override
public Bundle respond(Bundle extras) {
return Bundle.EMPTY;
}
private void maybeLogQueryToEventLog(
long durationMillis, Uri uri, String[] projection, @Nullable Bundle queryArgs) {
if (!ENABLE_CONTENT_SAMPLE) return;
int samplePercent = samplePercentForDuration(durationMillis);
if (samplePercent < 100) {
synchronized (mRandom) {
if (mRandom.nextInt(100) >= samplePercent) {
return;
}
}
}
// Ensure a non-null bundle.
queryArgs = (queryArgs != null) ? queryArgs : Bundle.EMPTY;
StringBuilder projectionBuffer = new StringBuilder(100);
if (projection != null) {
for (int i = 0; i < projection.length; ++i) {
// Note: not using a comma delimiter here, as the
// multiple arguments to EventLog.writeEvent later
// stringify with a comma delimiter, which would make
// parsing uglier later.
if (i != 0) projectionBuffer.append('/');
projectionBuffer.append(projection[i]);
}
}
// ActivityThread.currentPackageName() only returns non-null if the
// current thread is an application main thread. This parameter tells
// us whether an event loop is blocked, and if so, which app it is.
String blockingPackage = AppGlobals.getInitialPackage();
EventLog.writeEvent(
EventLogTags.CONTENT_QUERY_SAMPLE,
uri.toString(),
projectionBuffer.toString(),
queryArgs.getString(QUERY_ARG_SQL_SELECTION, ""),
queryArgs.getString(QUERY_ARG_SQL_SORT_ORDER, ""),
durationMillis,
blockingPackage != null ? blockingPackage : "",
samplePercent);
}
@Override public Bundle getExtras() {
return Bundle.EMPTY;
}
@Override
public Bundle respond(Bundle extras) {
return Bundle.EMPTY;
}
/**
* android 2.3 没有此函数,4.0 以后是个隐藏函数。
*/
public void setExtras(Bundle extras) {
mExtras = (extras == null) ? Bundle.EMPTY : extras;
}
public static Bundle e(Context context) {
ApplicationInfo b = b(context);
return (b == null || b.metaData == null) ? Bundle.EMPTY : b.metaData;
}
@Override
public void setExtras(Bundle extras) {
mExtras = (extras == null) ? Bundle.EMPTY : extras;
}
@Override
public Bundle respond(Bundle extras) {
return Bundle.EMPTY;
}
/**
* Get the extras associated with a given widget instance.
* <p>
* The extras can be used to embed additional information about this widget to be accessed
* by the associated widget's AppWidgetProvider.
*
* @see #updateAppWidgetOptions(int, Bundle)
*
* @param appWidgetId The AppWidget instances for which to set the RemoteViews.
* @return The options associated with the given widget instance.
*/
public Bundle getAppWidgetOptions(int appWidgetId) {
if (mService == null) {
return Bundle.EMPTY;
}
try {
return mService.getAppWidgetOptions(mPackageName, appWidgetId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Implement this to handle query requests where the arguments are packed into a {@link Bundle}.
* Arguments may include traditional SQL style query arguments. When present these
* should be handled according to the contract established in
* {@link #query(Uri, String[], String, String[], String, CancellationSignal).
*
* <p>Traditional SQL arguments can be found in the bundle using the following keys:
* <li>{@link ContentResolver#QUERY_ARG_SQL_SELECTION}
* <li>{@link ContentResolver#QUERY_ARG_SQL_SELECTION_ARGS}
* <li>{@link ContentResolver#QUERY_ARG_SQL_SORT_ORDER}
*
* <p>This method can be called from multiple threads, as described in
* <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
* and Threads</a>.
*
* <p>
* Example client call:<p>
* <pre>// Request 20 records starting at row index 30.
Bundle queryArgs = new Bundle();
queryArgs.putInt(ContentResolver.QUERY_ARG_OFFSET, 30);
queryArgs.putInt(ContentResolver.QUERY_ARG_LIMIT, 20);
Cursor cursor = getContentResolver().query(
contentUri, // Content Uri is specific to individual content providers.
projection, // String[] describing which columns to return.
queryArgs, // Query arguments.
null); // Cancellation signal.</pre>
*
* Example implementation:<p>
* <pre>
int recordsetSize = 0x1000; // Actual value is implementation specific.
queryArgs = queryArgs != null ? queryArgs : Bundle.EMPTY; // ensure queryArgs is non-null
int offset = queryArgs.getInt(ContentResolver.QUERY_ARG_OFFSET, 0);
int limit = queryArgs.getInt(ContentResolver.QUERY_ARG_LIMIT, Integer.MIN_VALUE);
MatrixCursor c = new MatrixCursor(PROJECTION, limit);
// Calculate the number of items to include in the cursor.
int numItems = MathUtils.constrain(recordsetSize - offset, 0, limit);
// Build the paged result set....
for (int i = offset; i < offset + numItems; i++) {
// populate row from your data.
}
Bundle extras = new Bundle();
c.setExtras(extras);
// Any QUERY_ARG_* key may be included if honored.
// In an actual implementation, include only keys that are both present in queryArgs
// and reflected in the Cursor output. For example, if QUERY_ARG_OFFSET were included
// in queryArgs, but was ignored because it contained an invalid value (like –273),
// then QUERY_ARG_OFFSET should be omitted.
extras.putStringArray(ContentResolver.EXTRA_HONORED_ARGS, new String[] {
ContentResolver.QUERY_ARG_OFFSET,
ContentResolver.QUERY_ARG_LIMIT
});
extras.putInt(ContentResolver.EXTRA_TOTAL_COUNT, recordsetSize);
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;</pre>
* <p>
* @see #query(Uri, String[], String, String[], String, CancellationSignal) for
* implementation details.
*
* @param uri The URI to query. This will be the full URI sent by the client.
* @param projection The list of columns to put into the cursor.
* If {@code null} provide a default set of columns.
* @param queryArgs A Bundle containing all additional information necessary for the query.
* Values in the Bundle may include SQL style arguments.
* @param cancellationSignal A signal to cancel the operation in progress,
* or {@code null}.
* @return a Cursor or {@code null}.
*/
public @Nullable Cursor query(@NonNull Uri uri, @Nullable String[] projection,
@Nullable Bundle queryArgs, @Nullable CancellationSignal cancellationSignal) {
queryArgs = queryArgs != null ? queryArgs : Bundle.EMPTY;
// if client doesn't supply an SQL sort order argument, attempt to build one from
// QUERY_ARG_SORT* arguments.
String sortClause = queryArgs.getString(ContentResolver.QUERY_ARG_SQL_SORT_ORDER);
if (sortClause == null && queryArgs.containsKey(ContentResolver.QUERY_ARG_SORT_COLUMNS)) {
sortClause = ContentResolver.createSqlSortClause(queryArgs);
}
return query(
uri,
projection,
queryArgs.getString(ContentResolver.QUERY_ARG_SQL_SELECTION),
queryArgs.getStringArray(ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS),
sortClause,
cancellationSignal);
}
/**
* @param nodeCompat The {@link SwitchAccessNodeCompat} to perform this action on
* @param id The id used to identify this action. Should correspond to a valid {@link
* AccessibilityActionCompat} id.
* @param label The human readable label used to identify this action
*/
public SwitchAccessAction(
SwitchAccessNodeCompat nodeCompat, int id, @Nullable CharSequence label) {
this(nodeCompat, id, label, Bundle.EMPTY);
}