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

Android examples for Android OS:Bundle Get

Description

Retrieves long value from bundle if present.

Demo Code


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

public class Main {
    public static final long DEFAULT_LONG_VALUE = 0l;

    /**/*from ww w  . j  ava  2s  .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