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

Android examples for android.os:Bundle

Description

get Int value from Bundle by key and handle null value

Demo Code

import android.os.Bundle;

public class Main {

  /**/*from   www.  j  av  a2s . com*/
   * get int
   * 
   * @param bundle
   * @param key
   * @return
   */
  public static Integer getInt(Bundle bundle, String key) {
    if (isEmpty(bundle, key)) {
      return null;
    } else {
      return bundle.getInt(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