本文整理了Java中android.os.Bundle.setClassLoader()
方法的一些代码示例,展示了Bundle.setClassLoader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bundle.setClassLoader()
方法的具体详情如下:
包路径:android.os.Bundle
类名称:Bundle
方法名:setClassLoader
暂无
代码示例来源:origin: stackoverflow.com
Bundle extras = getIntent().getExtras();
extras.setClassLoader(TestParcel.class.getClassLoader());
TestParcel cfgOptions = extras.getParcelable("cfgOptions");
代码示例来源:origin: AltBeacon/android-beacon-library
public static SettingsData fromBundle(@NonNull Bundle bundle) {
bundle.setClassLoader(Region.class.getClassLoader());
SettingsData settingsData = null;
if (bundle.get(SETTINGS_DATA_KEY) != null) {
settingsData = (SettingsData) bundle.getSerializable(SETTINGS_DATA_KEY);
}
return settingsData;
}
代码示例来源:origin: AltBeacon/android-beacon-library
public static RangingData fromBundle(Bundle bundle) {
bundle.setClassLoader(Region.class.getClassLoader());
Region region = null;
Collection<Beacon> beacons = null;
if (bundle.get(BEACONS_KEY) != null) {
beacons = (Collection<Beacon>) bundle.getSerializable(BEACONS_KEY);
}
if (bundle.get(REGION_KEY) != null) {
region = (Region) bundle.getSerializable(REGION_KEY);
}
return new RangingData(beacons, region);
}
代码示例来源:origin: AltBeacon/android-beacon-library
public static MonitoringData fromBundle(Bundle bundle) {
bundle.setClassLoader(Region.class.getClassLoader());
Region region = null;
if (bundle.get(REGION_KEY) != null) {
region = (Region) bundle.getSerializable(REGION_KEY);
}
Boolean inside = bundle.getBoolean(INSIDE_KEY);
return new MonitoringData(inside, region);
}
代码示例来源:origin: AltBeacon/android-beacon-library
public static StartRMData fromBundle(@NonNull Bundle bundle) {
bundle.setClassLoader(Region.class.getClassLoader());
boolean valid = false;
StartRMData data = new StartRMData();
if (bundle.containsKey(REGION_KEY)) {
data.mRegion = (Region)bundle.getSerializable(REGION_KEY);
valid = true;
}
if (bundle.containsKey(SCAN_PERIOD_KEY)) {
data.mScanPeriod = (Long) bundle.get(SCAN_PERIOD_KEY);
valid = true;
}
if (bundle.containsKey(BETWEEN_SCAN_PERIOD_KEY)) {
data.mBetweenScanPeriod = (Long) bundle.get(BETWEEN_SCAN_PERIOD_KEY);
}
if (bundle.containsKey(BACKGROUND_FLAG_KEY)) {
data.mBackgroundFlag = (Boolean) bundle.get(BACKGROUND_FLAG_KEY);
}
if (bundle.containsKey(CALLBACK_PACKAGE_NAME_KEY)) {
data.mCallbackPackageName = (String) bundle.get(CALLBACK_PACKAGE_NAME_KEY);
}
if (valid) {
return data;
}
else {
return null;
}
}
代码示例来源:origin: AppIntro/AppIntro
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
if (state != null) {
Bundle bundle = (Bundle) state;
bundle.setClassLoader(loader);
Parcelable[] fss = bundle.getParcelableArray("states");
mSavedState.clear();
mFragments.clear();
if (fss != null) {
for (int i = 0; i < fss.length; i++) {
mSavedState.add((Fragment.SavedState) fss[i]);
}
}
Iterable<String> keys = bundle.keySet();
for (String key : keys) {
if (key.startsWith("f")) {
int index = Integer.parseInt(key.substring(1));
Fragment f = mFragmentManager.getFragment(bundle, key);
if (f != null) {
while (mFragments.size() <= index) {
mFragments.add(null);
}
f.setMenuVisibility(false);
mFragments.set(index, f);
}
}
}
}
}
}
代码示例来源:origin: aa112901/remusic
if (state != null) {
Bundle bundle = (Bundle)state;
bundle.setClassLoader(loader);
Parcelable[] fss = bundle.getParcelableArray("states");
mSavedState.clear();
代码示例来源:origin: bluelinelabs/Conductor
private void restoreViewState(@NonNull View view) {
if (viewState != null) {
view.restoreHierarchyState(viewState.getSparseParcelableArray(KEY_VIEW_STATE_HIERARCHY));
Bundle savedViewState = viewState.getBundle(KEY_VIEW_STATE_BUNDLE);
savedViewState.setClassLoader(getClass().getClassLoader());
onRestoreViewState(view, savedViewState);
restoreChildControllerHosts();
List<LifecycleListener> listeners = new ArrayList<>(lifecycleListeners);
for (LifecycleListener lifecycleListener : listeners) {
lifecycleListener.onRestoreViewState(this, viewState);
}
}
}
代码示例来源:origin: bluelinelabs/Conductor
@NonNull
static Controller newInstance(@NonNull Bundle bundle) {
final String className = bundle.getString(KEY_CLASS_NAME);
//noinspection ConstantConditions
Class cls = ClassUtils.classForName(className, false);
Constructor[] constructors = cls.getConstructors();
Constructor bundleConstructor = getBundleConstructor(constructors);
Bundle args = bundle.getBundle(KEY_ARGS);
if (args != null) {
args.setClassLoader(cls.getClassLoader());
}
Controller controller;
try {
if (bundleConstructor != null) {
controller = (Controller)bundleConstructor.newInstance(args);
} else {
//noinspection ConstantConditions
controller = (Controller)getDefaultConstructor(constructors).newInstance();
// Restore the args that existed before the last process death
if (args != null) {
controller.args.putAll(args);
}
}
} catch (Exception e) {
throw new RuntimeException("An exception occurred while creating a new instance of " + className + ". " + e.getMessage(), e);
}
controller.restoreInstanceState(bundle);
return controller;
}
代码示例来源:origin: bluelinelabs/Conductor
private void restoreInstanceState(@NonNull Bundle savedInstanceState) {
viewState = savedInstanceState.getBundle(KEY_VIEW_STATE);
if (viewState != null) {
viewState.setClassLoader(getClass().getClassLoader());
}
instanceId = savedInstanceState.getString(KEY_INSTANCE_ID);
targetInstanceId = savedInstanceState.getString(KEY_TARGET_INSTANCE_ID);
requestedPermissions.addAll(savedInstanceState.getStringArrayList(KEY_REQUESTED_PERMISSIONS));
overriddenPushHandler = ControllerChangeHandler.fromBundle(savedInstanceState.getBundle(KEY_OVERRIDDEN_PUSH_HANDLER));
overriddenPopHandler = ControllerChangeHandler.fromBundle(savedInstanceState.getBundle(KEY_OVERRIDDEN_POP_HANDLER));
needsAttach = savedInstanceState.getBoolean(KEY_NEEDS_ATTACH);
retainViewMode = RetainViewMode.values()[savedInstanceState.getInt(KEY_RETAIN_VIEW_MODE, 0)];
List<Bundle> childBundles = savedInstanceState.getParcelableArrayList(KEY_CHILD_ROUTERS);
for (Bundle childBundle : childBundles) {
ControllerHostedRouter childRouter = new ControllerHostedRouter();
childRouter.restoreInstanceState(childBundle);
childRouters.add(childRouter);
}
this.savedInstanceState = savedInstanceState.getBundle(KEY_SAVED_STATE);
if (this.savedInstanceState != null) {
this.savedInstanceState.setClassLoader(getClass().getClassLoader());
}
performOnRestoreInstanceState();
}
代码示例来源:origin: stackoverflow.com
public int onStartCommand(Intent intent, int flags, int startId) {
try {
// assuming SignerClient activity is located in the package "com.example.client.A"
Context context = createPackageContext("com.example.client.A", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
ClassLoader cl = context.getClassLoader();
Bundle bundle = intent.getExtras();
bundle.setClassLoader(cl);
ResultReceiver rr = bundle.getParcelable("resultreceiver");
//... your interaction with ResultReceiver ...
rr.send(1, null); // will result in a onReceiveResult call in the client activity
} catch (NameNotFoundException e) {
Log.e("MyService", "SignerClient package context was not found", e);
throw new RuntimeException(e);
}
return START_STICKY;
}
代码示例来源:origin: stackoverflow.com
//Create parcelable object and put to Bundle
Question q = new Question(questionId, surveyServerId, title, type, answers);
Bundle b = new Bundle();
b.putParcelable("someTag", q);
//Save bundle to parcel
Parcel parcel = Parcel.obtain();
b.writeToParcel(parcel, 0);
//Extract bundle from parcel
parcel.setDataPosition(0);
Bundle b2 = parcel.readBundle();
b2.setClassLoader(Question.class.getClassLoader());
Question q2 = b2.getParcelable("someTag");
//Check that objects are not same and test that objects are equal
assertFalse("Bundle is the same", b2 == b);
assertFalse("Question is the same", q2 == q);
assertTrue("Questions aren't equal", q2.equals(q));
代码示例来源:origin: limpoxe/Android-Plugin-Framework
@Override
public void callActivityOnPostCreate(Activity activity, Bundle icicle) {
PluginInjector.injectInstrumetionFor360Safe(activity, this);
if (icicle != null) {
icicle.setClassLoader(activity.getClassLoader());
}
real.callActivityOnPostCreate(activity, icicle);
}
代码示例来源:origin: limpoxe/Android-Plugin-Framework
@Override
public void callActivityOnSaveInstanceState(Activity activity, Bundle outState) {
PluginInjector.injectInstrumetionFor360Safe(activity, this);
if (outState != null) {
outState.setClassLoader(activity.getClassLoader());
}
real.callActivityOnSaveInstanceState(activity, outState);
}
代码示例来源:origin: limpoxe/Android-Plugin-Framework
@Override
public void callActivityOnRestoreInstanceState(Activity activity, Bundle savedInstanceState) {
PluginInjector.injectInstrumetionFor360Safe(activity, this);
if (savedInstanceState != null) {
savedInstanceState.setClassLoader(activity.getClassLoader());
}
real.callActivityOnRestoreInstanceState(activity, savedInstanceState);
}
代码示例来源:origin: stackoverflow.com
public void onReceive(Context context, Intent intent) {
Bundle extras=intent.getExtras();
extras.setClassLoader(getClass().getClassLoader());
MyCustomResponseMsg message = new MyCustomResponseMsg((MyMessage) extras.getParcelable(MyMessage.EXTRA_MESSAGE_KEY));
//...
}
代码示例来源:origin: com.google.android/support-v4
SavedState(Parcel in, ClassLoader loader) {
mState = in.readBundle();
if (loader != null && mState != null) {
mState.setClassLoader(loader);
}
}
代码示例来源:origin: ManbangGroup/Phantom
@Nullable
private Bundle getPluginSavedData(Bundle savedInstanceState) {
Bundle savedData = null;
if (null != savedInstanceState) {
savedData = savedInstanceState.getBundle(Constants.PLUGIN_SAVED_DATA);
if (null != savedData) {
savedData.setClassLoader(mClassLoader);
}
}
return savedData;
}
代码示例来源:origin: stackoverflow.com
Bundle data = msg.getData();
data.setClassLoader(this.getClass().getClassLoader());
Parcelable parcelable = data.getParcelable("KEY");
if (parcelable instanceof ContentValues) {
ContentValues cv = (ContentValues) parcelable;
Log.d(TAG, "reply content: " + cv.getAsInteger("KEY"));
}
Parcelable parcelable2 = data.getParcelable("KEY2");
if (parcelable2 instanceof TPServiceDataModal) {
TPServiceDataModal modal = (TPServiceDataModal) parcelable2;
Log.d(TAG, "reply modal: " + modal.mData);
}
代码示例来源:origin: limpoxe/Android-Plugin-Framework
icicle.setClassLoader(activity.getClassLoader());
内容来源于网络,如有侵权,请联系作者删除!