Retrieves int value from bundle if present. - Android Android OS

Android examples for Android OS:Bundle Get

Description

Retrieves int value from bundle if present.

Demo Code


//package com.book2s;
import android.os.Bundle;

public class Main {
    public static final int DEFAULT_INT_VALUE = 0;

    /**//from  w  w w.  j  a  v  a  2  s  .  c  o m
     * Retrieves int value from bundle if present.
     *
     * @param bundle to get from
     * @param key    to search by
     * @return value or {@link #DEFAULT_INT_VALUE} if nothing found
     */
    public static int getInt(Bundle bundle, String key) {
        if (bundle != null && bundle.containsKey(key)) {
            return bundle.getInt(key);
        } else {
            return DEFAULT_INT_VALUE;
        }
    }
}

Related Tutorials