get Long value from Bundle by key and handle null value - Android android.os

Android examples for android.os:Bundle

Description

get Long value from Bundle by key and handle null value

Demo Code

import android.os.Bundle;

public class Main {

  /**/*from  w  w w .  jav  a 2 s  .  com*/
   * get Long
   * 
   * @param bundle
   * @param key
   * @return
   */
  public static Long getLong(Bundle bundle, String key) {
    if (isEmpty(bundle, key)) {
      return null;
    } else {
      return bundle.getLong(key);
    }
  }

  /**
   * check whether a key is empty
   * 
   * @param bundle
   * @param key
   * @return
   */
  public static boolean isEmpty(Bundle bundle, String key) {
    return bundle == null || !bundle.containsKey(key);
  }

}

Related Tutorials