get int from Bundle by key - Android Android OS

Android examples for Android OS:Bundle Key

Description

get int from Bundle by key

Demo Code


//package com.book2s;

import android.os.Bundle;

public class Main {
    /**/*from  ww  w .j  av  a2s.c  o m*/
     * 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