Java Code Examples for android.os.Bundle.setClassLoader()

The following are Jave code examples for showing how to use setClassLoader() of the android.os.Bundle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PicShow-zhaipin   File: FragmentListPageAdapter.java   View Source Code Vote up 7 votes
@Override
    public void restoreState(Parcelable state, ClassLoader loader) {
        if (state != null) {
            Bundle bundle = (Bundle) state;
            bundle.setClassLoader(loader);
            mSavedState.clear();
            mFragments.clear();
            if (bundle.containsKey("states")) {
                mSavedState = bundle.getSparseParcelableArray("states");
            }
            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) {
                        f.setMenuVisibility(false);
                        mFragments.put(index, f);
                    } else {
//						Log.w(TAG, "Bad fragment at key " + key);
                    }
                }
            }
        }
    }
 
Example 2
Project: DroidPlugin   File: PluginCallback.java   View Source Code Vote up 6 votes
private void setIntentClassLoader(Intent intent, ClassLoader classLoader) {
    try {
        Bundle mExtras = (Bundle) FieldUtils.readField(intent, "mExtras");
        if (mExtras != null) {
            mExtras.setClassLoader(classLoader);
        } else {
            Bundle value = new Bundle();
            value.setClassLoader(classLoader);
            FieldUtils.writeField(intent, "mExtras", value);
        }
    } catch (Exception e) {
    } finally {
        intent.setExtrasClassLoader(classLoader);
    }
}
 
Example 3
Project: imageviewer   File: RecyclingPagerAdapter.java   View Source Code Vote up 6 votes
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        SparseArray<Parcelable> ss = bundle.containsKey(STATE) ? bundle.getSparseParcelableArray(STATE) : null;
        mSavedStates = ss != null ? ss : new SparseArray<Parcelable>();
    }
    super.restoreState(state, loader);
}
 
Example 4
Project: Stage   File: Scene.java   View Source Code Vote up 6 votes
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);
    if (savedViewState != null) {
      savedViewState.setClassLoader(getClass().getClassLoader());
      onRestoreViewState(view, savedViewState);
    }

    if (!lifecycleListeners.isEmpty()) {
      for (LifecycleListener listener : new ArrayList<>(lifecycleListeners)) {
        listener.onRestoreViewState(this, viewState);
      }
    }
  }
}
 
Example 5
Project: DroidIPC   File: BundleSender.java   View Source Code Vote up 6 votes
public Bundle send(Bundle bundle) {
	
	Parcel data = Parcel.obtain();
	data.writeBundle(bundle);
	
	Parcel reply = Parcel.obtain();
	
	try {
		mService.transact(ServiceContext.TRANSACT_BUNDLE_SENDER, data, reply, 0);
		
		Bundle result = reply.readBundle();
		result.setClassLoader(getClass().getClassLoader());
		return result;
		
	} catch (RemoteException e) {
		e.printStackTrace();
		return null;
	} finally {
		data.recycle();
		reply.recycle();
	}
	
}
 
Example 6
Project: IPCInvoker   File: BaseIPCService.java   View Source Code Vote up 6 votes
@Override
public Bundle invokeSync(Bundle data, String clazz) throws RemoteException {
    if (clazz == null || clazz.length() == 0) {
        Log.e(TAG, "invokeAsync failed, class is null or nil.");
        return null;
    }
    IPCSyncInvokeTask task = ObjectStore.get(clazz, IPCSyncInvokeTask.class);
    if (task == null) {
        Log.e(TAG, "invokeSync failed, can not newInstance by class %s.", clazz);
        return null;
    }
    if (data != null) {
        data.setClassLoader(BaseIPCService.class.getClassLoader());
    }
    return task.invoke(data);
}
 
Example 7
Project: boohee_v5.6   File: MediaBrowserCompat.java   View Source Code Vote up 6 votes
public void handleMessage(Message msg) {
    if (this.mCallbacksMessengerRef != null) {
        Bundle data = msg.getData();
        data.setClassLoader(MediaSessionCompat.class.getClassLoader());
        switch (msg.what) {
            case 1:
                this.mCallbackImpl.onServiceConnected((Messenger) this.mCallbacksMessengerRef.get(), data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), (Token) data.getParcelable(MediaBrowserProtocol.DATA_MEDIA_SESSION_TOKEN), data.getBundle(MediaBrowserProtocol.DATA_ROOT_HINTS));
                return;
            case 2:
                this.mCallbackImpl.onConnectionFailed((Messenger) this.mCallbacksMessengerRef.get());
                return;
            case 3:
                this.mCallbackImpl.onLoadChildren((Messenger) this.mCallbacksMessengerRef.get(), data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), data.getParcelableArrayList(MediaBrowserProtocol.DATA_MEDIA_ITEM_LIST), data.getBundle(MediaBrowserProtocol.DATA_OPTIONS));
                return;
            default:
                Log.w(MediaBrowserCompat.TAG, "Unhandled message: " + msg + "\n  Client version: " + 1 + "\n  Service version: " + msg.arg1);
                return;
        }
    }
}
 
Example 8
Project: letv   File: MediaBrowserCompat.java   View Source Code Vote up 6 votes
public void handleMessage(Message msg) {
    if (this.mCallbacksMessengerRef != null) {
        Bundle data = msg.getData();
        data.setClassLoader(MediaSessionCompat.class.getClassLoader());
        switch (msg.what) {
            case 1:
                this.mCallbackImpl.onServiceConnected((Messenger) this.mCallbacksMessengerRef.get(), data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), (Token) data.getParcelable(MediaBrowserProtocol.DATA_MEDIA_SESSION_TOKEN), data.getBundle(MediaBrowserProtocol.DATA_ROOT_HINTS));
                return;
            case 2:
                this.mCallbackImpl.onConnectionFailed((Messenger) this.mCallbacksMessengerRef.get());
                return;
            case 3:
                this.mCallbackImpl.onLoadChildren((Messenger) this.mCallbacksMessengerRef.get(), data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), data.getParcelableArrayList(MediaBrowserProtocol.DATA_MEDIA_ITEM_LIST), data.getBundle(MediaBrowserProtocol.DATA_OPTIONS));
                return;
            default:
                Log.w(MediaBrowserCompat.TAG, "Unhandled message: " + msg + "\n  Client version: " + 1 + "\n  Service version: " + msg.arg1);
                return;
        }
    }
}
 
Example 9
Project: SlotNSlot_Android   File: DownloaderClientMarshaller.java   View Source Code Vote up 6 votes
@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case MSG_ONDOWNLOADPROGRESS:                        
            Bundle bun = msg.getData();
            if ( null != mContext ) {
                bun.setClassLoader(mContext.getClassLoader());
                DownloadProgressInfo dpi = (DownloadProgressInfo) msg.getData()
                        .getParcelable(PARAM_PROGRESS);
                mItf.onDownloadProgress(dpi);
            }
            break;
        case MSG_ONDOWNLOADSTATE_CHANGED:
            mItf.onDownloadStateChanged(msg.getData().getInt(PARAM_NEW_STATE));
            break;
        case MSG_ONSERVICECONNECTED:
            mItf.onServiceConnected(
                    (Messenger) msg.getData().getParcelable(PARAM_MESSENGER));
            break;
    }
}
 
Example 10
Project: GitHub   File: ParcelUtils.java   View Source Code Vote up 5 votes
public static Parcelable readFromParcel(Parcel parcel, Class<?> parcelableType, String key) {
    parcel.setDataPosition(0);

    Bundle bundle = parcel.readBundle();
    bundle.setClassLoader(parcelableType.getClassLoader());
    
    Parcelable unparceledInstance = bundle.getParcelable(key);
    return unparceledInstance;
}
 
Example 11
Project: Orin   File: CustomFragmentStatePagerAdapter.java   View Source Code Vote up 5 votes
@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);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 12
Project: RetroMusicPlayer   File: CustomFragmentStatePagerAdapter.java   View Source Code Vote up 5 votes
@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);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 13
Project: Allshare   File: WXEntryActivity.java   View Source Code Vote up 5 votes
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    wxapi = WXAPIFactory.createWXAPI(this, AllShare.getWxId(), true);
    boolean registered = wxapi.registerApp(AllShare.getWxId());
    // 若是接收结果,处理完直接finish
    if (wxapi.handleIntent(intent, this)) {
        finish();
        return;
    }

    Bundle bundle;
    boolean paramError = false;
    if (!registered) {
        LogUtils.e("%s: api is null, finish.", TAG);
        paramError = true;
    } else if (null == intent || null == (bundle = intent.getExtras())) {
        LogUtils.e("%s: params is null, finish.", TAG);
        paramError = true;
    } else {
        bundle.setClassLoader(WXContent.class.getClassLoader());
        if (null == (shareContent = bundle.getParcelable(KEY_SHARE_CONTENT))) {
            LogUtils.e("%s: share content is null, finish.", TAG);
            paramError = true;
        } else if (null == (listener = bundle.getParcelable(KEY_SHARE_LISTENER))) {
            LogUtils.e("%s: result receiver is null.", TAG);
        }
    }
    if (paramError) {
        Toast.makeText(this, R.string.share_failed, Toast.LENGTH_SHORT).show();
        finish();
        return;
    }

    share();
}
 
Example 14
Project: letv   File: FragmentStatePagerAdapter.java   View Source Code Vote up 5 votes
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        this.mSavedState.clear();
        this.mFragments.clear();
        if (fss != null) {
            for (Parcelable parcelable : fss) {
                this.mSavedState.add((SavedState) parcelable);
            }
        }
        for (String key : bundle.keySet()) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = this.mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (this.mFragments.size() <= index) {
                        this.mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    this.mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 15
Project: aos-Video   File: ManualShowScrappingSearchFragment.java   View Source Code Vote up 5 votes
private HashMap<String, EpisodeTags> toMap(Bundle b) {
    int size = (b!=null) ? b.size() : 0;
    HashMap<String, EpisodeTags> result = new HashMap<String, EpisodeTags>(size);
    if (b != null) {
        b.setClassLoader(BaseTags.class.getClassLoader());
        for (String key : b.keySet()) {
            result.put(key, b.<EpisodeTags>getParcelable(key));
        }
    }
    return result;
}
 
Example 16
Project: letv   File: MediaBrowserCompat.java   View Source Code Vote up 5 votes
protected void onReceiveResult(int resultCode, Bundle resultData) {
    resultData.setClassLoader(MediaBrowserCompat.class.getClassLoader());
    if (resultCode == 0 && resultData != null && resultData.containsKey(MediaBrowserServiceCompat.KEY_MEDIA_ITEM)) {
        Parcelable item = resultData.getParcelable(MediaBrowserServiceCompat.KEY_MEDIA_ITEM);
        if (item instanceof MediaItem) {
            this.mCallback.onItemLoaded((MediaItem) item);
            return;
        } else {
            this.mCallback.onError(this.mMediaId);
            return;
        }
    }
    this.mCallback.onError(this.mMediaId);
}
 
Example 17
Project: javaide   File: ArrayPagerAdapter.java   View Source Code Vote up 5 votes
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle b = (Bundle) state;

        b.setClassLoader(getClass().getClassLoader());

        entries = ((Bundle) state).getParcelableArrayList(KEY_DESCRIPTORS);
        notifyDataSetChanged();
    }
}
 
Example 18
Project: javaide   File: ArrayPagerAdapter.java   View Source Code Vote up 5 votes
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle b = (Bundle) state;

        b.setClassLoader(getClass().getClassLoader());

        entries = ((Bundle) state).getParcelableArrayList(KEY_DESCRIPTORS);
        notifyDataSetChanged();
    }
}
 
Example 19
Project: boohee_v5.6   File: FragmentStatePagerAdapter.java   View Source Code Vote up 5 votes
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        this.mSavedState.clear();
        this.mFragments.clear();
        if (fss != null) {
            for (Parcelable parcelable : fss) {
                this.mSavedState.add((SavedState) parcelable);
            }
        }
        for (String key : bundle.keySet()) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = this.mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (this.mFragments.size() <= index) {
                        this.mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    this.mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 20
Project: boohee_v5.6   File: MediaBrowserServiceCompat.java   View Source Code Vote up 4 votes
public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
    Bundle data = msg.getData();
    data.setClassLoader(MediaBrowserCompat.class.getClassLoader());
    data.putInt(MediaBrowserProtocol.DATA_CALLING_UID, Binder.getCallingUid());
    return super.sendMessageAtTime(msg, uptimeMillis);
}