List of usage examples for android.os Bundle setClassLoader
@Override public void setClassLoader(ClassLoader loader)
From source file:Main.java
public static <T> Map<String, T> fromBundle(Bundle input, Class<T> claz) { input.setClassLoader(claz.getClassLoader()); Map<String, T> output = new ArrayMap<String, T>(); for (String key : input.keySet()) { output.put(key, (T) input.get(key)); }// w w w. j a v a 2s. co m return output; }
From source file:Main.java
/** * Create a Parcelable Bundle containing a String message for transport to the test package engine. * The String message is stored via Bundle.putString using {@link #BUNDLE_MESSAGE} as the key for the item. * @param message to send across processes. * @return Parcelable Bundle//from w w w .ja v a2s . co m * @see Bundle#putString(String, String) * @see Bundle#getString(String) */ public static Parcelable setParcelableMessage(String message) { Bundle bundle = new Bundle(); bundle.putString(BUNDLE_MESSAGE, message); bundle.setClassLoader(Bundle.class.getClassLoader()); return bundle; }
From source file:Main.java
/** * Create a Parcelable Bundle containing a char[] for transport to the test package engine. * The char[] message is stored via Bundle.putCharArray using {@link #BUNDLE_PROPERTIES} as the key for the item. * The original intent here is to store Java Properties in the Bundle that were serialized via * the Java Properties.store method.<br> * NOTE: This has not yet been tested!/*from ww w .j a va 2s .com*/ * @param char[] (Properties) to send across processes. * @return Parcelable Bundle * @see Bundle#putCharArray(String, char[]) * @see Bundle#getCharArray(String) */ public static Parcelable setParcelableProps(char[] bytes) { Bundle bundle = new Bundle(); bundle.putCharArray(BUNDLE_PROPERTIES, bytes); bundle.setClassLoader(Bundle.class.getClassLoader()); return bundle; }
From source file:Main.java
/** * Create a Parcelable Bundle containing 3 parameters: String, int, int for transport from the test package engine.<br> * It will be used by {@link Message#setData(Bundle)} for sending a part of whole message from engine.<br> * The String message is stored via Bundle.putCharArray using {@link #BUNDLE_SMALL_PARCEL_ID} as the key for the item.<br> * The int message is stored via Bundle.putCharArray using {@link #BUNDLE_SMALL_PARCEL_INDEX} as the key for the item.<br> * The int message is stored via Bundle.putCharArray using {@link #BUNDLE_SMALL_PARCEL_TOTALNUMBER} as the key for the item.<br> * /*from ww w . j a va 2 s. c o m*/ * @param ID String, the message's ID. * @param index int, the index of this parcel of the whole message. * @param totalNumber int, indicate the total number of parcels will be sent for a whole message.. * @return Parcelable Bundle * @see Bundle#putCharArray(String, char[]) * @see Bundle#getCharArray(String) * @see #getParcelableIDFromSmallParcel(Parcelable) * @see #getParcelableIndexFromSmallParcel(Parcelable) * @see #getParcelableTotalNumberFromSmallParcel(Parcelable) * @see #isSmallParcelOfWholeMessage(Bundle) */ public static Bundle setBundleOfSmallParcel(String ID, int index, int totalNumber) { Bundle bundle = new Bundle(); bundle.putString(BUNDLE_SMALL_PARCEL_ID, ID); bundle.putInt(BUNDLE_SMALL_PARCEL_INDEX, index); bundle.putInt(BUNDLE_SMALL_PARCEL_TOTALNUMBER, totalNumber); bundle.setClassLoader(Bundle.class.getClassLoader()); return bundle; }
From source file:ch.citux.td.ui.fragments.TDFragment.java
public static <T extends Fragment> T instantiate(Class<T> clazz, Bundle args) { try {//from w ww . ja v a 2s .c om T fragment = clazz.newInstance(); if (args != null) { args.setClassLoader(clazz.getClassLoader()); fragment.setArguments(args); } return fragment; } catch (Exception e) { throw new InstantiationException("Unable to instantiate fragment " + clazz + ": make sure class name exists, is public, and has an" + " empty constructor that is public", e); } }
From source file:Main.java
/** * Concatenate two Parcelable Bundles containing String to form one Parcelable.<br> * The String message is stored via Bundle.putCharArray using {@link #BUNDLE_MESSAGE} as the key for the item.<br> * //from www . j a va2 s. c o m * @param one Parcelable Bundle, containing String message * @param another Parcelable Bundle, containing String message * @return Parcelable Bundle, including Parcelable one and another. * @see Bundle#putCharArray(String, char[]) * @see Bundle#getCharArray(String) */ public static Parcelable assembleParcelMessage(Parcelable one, Parcelable another) { Bundle bundle = new Bundle(); String message = ""; String tmp = null; if (one != null) { tmp = ((Bundle) one).getString(BUNDLE_MESSAGE); if (tmp != null) message += tmp; } if (another != null) { tmp = ((Bundle) another).getString(BUNDLE_MESSAGE); if (tmp != null) message += tmp; } bundle.putString(BUNDLE_MESSAGE, message); bundle.setClassLoader(Bundle.class.getClassLoader()); return bundle; }
From source file:by.zatta.pilight.connection.ConnectionService.java
/** * Send the data to all clients.//from w w w.j av a 2 s. c o m * * @param message * The message to send. */ private static void sendMessageToUI(int what, String message) { // Log.v(TAG, "sent message called, clients attached: " + Integer.toString(mClients.size())); Iterator<Messenger> messengerIterator = mClients.iterator(); while (messengerIterator.hasNext()) { Messenger messenger = messengerIterator.next(); try { Bundle bundle = new Bundle(); bundle.setClassLoader(aCtx.getClassLoader()); switch (what) { case MSG_SET_STATUS: // Log.v(TAG, "setting status: " + message); bundle.putString("status", message); Message msg_string = Message.obtain(null, MSG_SET_STATUS); msg_string.setData(bundle); messenger.send(msg_string); break; case MSG_SET_BUNDLE: if (!mDevices.isEmpty()) { // Log.v(TAG, "putting mDevices"); bundle.putParcelableArrayList("config", (ArrayList<? extends Parcelable>) mDevices); Message msg = Message.obtain(null, MSG_SET_BUNDLE); msg.setData(bundle); messenger.send(msg); } break; } } catch (RemoteException e) { Log.w(TAG, "mClients.remove called"); mClients.remove(messenger); } } }
From source file:com.bmd.android.collection.example.EnhancedArrayMapTest.java
public void testParcelable() { final Bundle bundle = new Bundle(); bundle.putParcelable("array", mArray); final Parcel parcel = Parcel.obtain(); bundle.writeToParcel(parcel, 0);//from www. ja v a 2 s .c o m parcel.setDataPosition(0); final Bundle out = parcel.readBundle(); out.setClassLoader(AndroidCollections.class.getClassLoader()); assertThat(out.getParcelable("array")).isEqualTo(mArray); }
From source file:org.opensilk.common.mortarflow.MortarPagerAdapter.java
@Override public void restoreState(Parcelable state, ClassLoader loader) { if (state == null || !(state instanceof Bundle)) return;/*from w w w . j av a2s .co m*/ Bundle b = (Bundle) state; b.setClassLoader(loader); savedState = b; }
From source file:org.xbmc.android.view.RelativePagerAdapter.java
@Override public void restoreState(Parcelable state, ClassLoader loader) { super.restoreState(state, loader); final Bundle bundle = (Bundle) state; bundle.setClassLoader(loader); currFragment = (RelativePagerFragment) fragmentManager.getFragment(bundle, "currentFragment"); }