get Date object from Bundle by Key - Android android.os

Android examples for android.os:Bundle

Description

get Date object from Bundle by Key

Demo Code

import java.util.Date;

import android.os.Bundle;

public class Main {

  private static final long INVALID_BUNDLE_MILLISECONDS = Long.MIN_VALUE;

  public static Date getDate(Bundle bundle, String key) {
    if (bundle == null) {
      return null;
    }//from w w  w.jav a2  s . c o  m

    long n = bundle.getLong(key, INVALID_BUNDLE_MILLISECONDS);
    if (n == INVALID_BUNDLE_MILLISECONDS) {
      return null;
    }

    return new Date(n);
  }

}

Related Tutorials