Retrieves string value from bundle if present. - Android android.os

Android examples for android.os:Bundle

Description

Retrieves string value from bundle if present.

Demo Code

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

public class Main{

    public static final String DEFAULT_STRING_VALUE = null;
    /**//from   w  w w  . ja  va2 s  . co m
     * Retrieves string value from bundle if present.
     *
     * @param bundle to get from
     * @param key    to search by
     * @return value or {@link #DEFAULT_STRING_VALUE} if nothing found
     */
    public static String getString(Bundle bundle, String key) {
        if (bundle != null && bundle.containsKey(key)) {
            return bundle.getString(key);
        } else {
            return DEFAULT_STRING_VALUE;
        }
    }

}

Related Tutorials