Example usage for android.os Bundle Bundle

List of usage examples for android.os Bundle Bundle

Introduction

In this page you can find the example usage for android.os Bundle Bundle.

Prototype

public Bundle() 

Source Link

Document

Constructs a new, empty Bundle.

Usage

From source file:Main.java

/**
 * Puts long value into a bundle. If bundle is null new one will be created.
 *
 * @param bundle to put into/*from w w w . j  ava 2  s  .  c  o  m*/
 * @param key    to put under
 * @param value  to put
 * @return bundle with the value
 */
public static Bundle putLong(Bundle bundle, String key, long value) {
    if (bundle == null) {
        bundle = new Bundle();
    }
    bundle.putLong(key, value);
    return bundle;
}

From source file:Main.java

public static Bundle createBundle(final String key, final String value) {
    final Bundle bundle = new Bundle();
    bundle.putString(key, value);//from  w  ww.j  a  va  2s  .  c  o  m
    return bundle;
}

From source file:Main.java

/**
 * Puts string value to bundle if passed and creates it if {@code null} passed.
 *
 * @param bundle to put into//w w w.  j a v a  2  s .  c  o  m
 * @param key    to to put under
 * @param value  to put
 * @return bundle with the newly put value
 */
public static Bundle putString(Bundle bundle, String key, String value) {
    if (bundle == null) {
        bundle = new Bundle();
    }
    bundle.putString(key, value);
    return bundle;
}

From source file:Main.java

/**
 * Puts boolean value to bundle if passed and creates it if {@code null} passed.
 *
 * @param bundle to put into//from w ww. j  a  va  2s .c om
 * @param key    to to put under
 * @param value  to put
 * @return bundle with the newly put value
 */
public static Bundle putBoolean(Bundle bundle, String key, Boolean value) {
    if (bundle == null) {
        bundle = new Bundle();
    }
    bundle.putBoolean(key, value);
    return bundle;
}

From source file:Main.java

public static void startActivityWithObjectForResult(Context context, Class<?> toClass, String key,
        Serializable obj, int requestCode) {
    Intent intent = new Intent();
    intent.setClass(context, toClass);/*from ww w  .  j a va 2 s  .  c o  m*/
    Bundle bundle = new Bundle();
    bundle.putSerializable(key, obj);
    intent.putExtras(bundle);
    //        int id =((IdObj)bundle.getSerializable("  ")).getId();
    ((Activity) context).startActivityForResult(intent, requestCode);
}

From source file:Main.java

/**
 * Decode parameters contained in the provided String and generate a {@link Bundle} associating
 * parameters name and values.//from   ww  w  .  jav a2 s  . c om
 * 
 * @param url
 *            Url that we decode parameters from.
 * @return Bundle containing decoded parameters.
 */
public static Bundle decodeUrl(String url) {
    Bundle bundle = new Bundle();
    if (!TextUtils.isEmpty(url) && url.indexOf("?") != -1) {
        String urlParameters = url.substring(url.indexOf("?") + 1);
        String[] parameters = urlParameters.split("&");
        for (String parameter : parameters) {
            String[] keyValue = parameter.split("=");
            if (keyValue.length == 2) {
                bundle.putString(URLDecoder.decode(keyValue[0]), URLDecoder.decode(keyValue[1]));
            }
        }
    }

    return bundle;
}

From source file:Main.java

public static Bundle getContactFromNumber(String number, Context context) {
    ContentResolver cr = context.getContentResolver();
    String[] projection = new String[] { Contacts._ID, Contacts.DISPLAY_NAME };
    Bundle bundle = new Bundle();
    Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(number));
    Cursor cursor = cr.query(contactUri, projection, null, null, null);
    try {//from  ww  w. j a  v  a2s.  c  om
        if (cursor.moveToFirst()) {
            for (String key : projection) {
                bundle.putString(key, cursor.getString(cursor.getColumnIndex(key)));
            }
        }
        return bundle;
    } catch (Exception e) {
        return null;
    } finally {
        cursor.close();
    }

}

From source file:Main.java

public static Bundle parseUrl(String url) {
    Bundle ret;/*from   www. ja  v  a 2 s  .co m*/
    url = url.replace("bdconnect", "http");
    try {
        URL urlParam = new URL(url);
        ret = decodeUrl(urlParam.getQuery());
        ret.putAll(decodeUrl(urlParam.getRef()));
        return ret;
    } catch (MalformedURLException e) {
        return new Bundle();
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
private static Bundle[] toBundleArray(ArrayList<HashMap> arrayList) {
    Bundle[] ret = new Bundle[arrayList.size()];
    for (int i = 0; i < ret.length; i++) {
        ret[i] = addMapToBundle(arrayList.get(i), new Bundle());
    }//from  www .  ja  va 2  s  . co  m
    return ret;
}

From source file:Main.java

public static Bundle urlToBundle(String url) {
    int index = url.indexOf("://");
    if (index >= 0) {
        url = "http://" + url.substring(index + 1);
    } else {/*  w  ww . j av  a  2s.  c  o  m*/
        url = "http://" + url;
    }

    try {
        URL e = new URL(url);
        Bundle b = decodeUrl(e.getQuery());
        b.putAll(decodeUrl(e.getRef()));
        return b;
    } catch (Throwable var4) {
        return new Bundle();
    }
}