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

Android examples for android.os:Bundle

Description

Retrieves long value from bundle if present.

Demo Code

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

public class Main{

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

}

Related Tutorials