contains Non Empty in Bundle by key - Android Android OS

Android examples for Android OS:Bundle Key

Description

contains Non Empty in Bundle by key

Demo Code


//package com.book2s;

import android.os.Bundle;
import java.util.ArrayList;

public class Main {
    public static boolean containsNonEmpty(Bundle b, String key) {
        Object o = b.get(key);/*from   ww w.  java 2s.com*/
        if (o == null) {
            return false;
        } else if (o instanceof String) {
            String s = (String) o;
            return s != null && !s.isEmpty();
        } else if (o instanceof byte[]) {
            byte a[] = (byte[]) o;
            return a != null && a.length != 0;
        } else if (o instanceof short[]) {
            short a[] = (short[]) o;
            return a != null && a.length != 0;
        } else if (o instanceof char[]) {
            char a[] = (char[]) o;
            return a != null && a.length != 0;
        } else if (o instanceof int[]) {
            int a[] = (int[]) o;
            return a != null && a.length != 0;
        } else if (o instanceof float[]) {
            float a[] = (float[]) o;
            return a != null && a.length != 0;
        } else if (o instanceof double[]) {
            double a[] = (double[]) o;
            return a != null && a.length != 0;
        } else if (o instanceof String[]) {
            String a[] = (String[]) o;
            return a != null && a.length != 0;
        } else if (o instanceof ArrayList) {
            ArrayList<?> a = (ArrayList<?>) o;
            return a != null && !a.isEmpty();
        }
        return o != null;
    }
}

Related Tutorials