get Bundle value by key As Int - Android android.os

Android examples for android.os:Bundle

Description

get Bundle value by key As Int

Demo Code

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

public class Main{

    public static int getAsInt(Bundle b, String key) {
        if (b == null) {
            return 0;
        }//from   w  w  w  . j a  va2s.co m
        if (!b.containsKey(key)) {
            return 0;
        }
        int value = 0;
        String s = b.getString(key);
        if (s == null) {
            try {
                value = b.getInt(key);
            } catch (ClassCastException e) {

            }
        } else {
            try {
                value = Integer.parseInt(s);
            } catch (NumberFormatException e) {

            }
        }
        return value;
    }

}

Related Tutorials