get Bundle value by key As Boolean - Android android.os

Android examples for android.os:Bundle

Description

get Bundle value by key As Boolean

Demo Code

import android.os.Bundle;

public class Main{

    public static boolean getAsBoolean(Bundle b, String key) {
        if (b == null) {
            return false;
        }//from w ww.j a v  a  2 s.c  om
        if (!b.containsKey(key)) {
            return false;
        }
        boolean value = false;
        String s = b.getString(key);
        if (s == null) {
            try {
                value = b.getBoolean(key);
            } catch (ClassCastException e) {

            }
        } else {
            try {
                value = Boolean.parseBoolean(s);
            } catch (NumberFormatException e) {

            }
        }
        return value;
    }

}

Related Tutorials