zoukankan      html  css  js  c++  java
  • 2017.6.26 工作记录

    Android 中传参数的时候经常需要传参数,有时候参数需要通过bundle进行传递,但每次都要写如下显得非常麻烦

    Bundle bundle = new Bundle();
    bundle.putSerializable("key2",...);
    bundle.putString("strKey",...);
    bundle.putInt("intKey",...);

    所以我就写了个工具类中使用的方法,只需传参数就可以了,方法暂时只支持String,int,boolean,实现接口的Serializable和Parcelable,欢迎使用这个方法

    public static ArrayList<String> bundleKeys;
        /**
         * 获取Bundle
         * @param objs
         * @return
         */
        public static Bundle getBundle(Object... objs){
            Bundle bundle = new Bundle();
            String key = "";
            bundleKeys = new ArrayList<>();
            for(int i = 0; i< objs.length ;i++){
                key = "obj"+(i+1);
                bundleKeys.add(key);
                if(objs[i] instanceof Integer){
                    bundle.putInt(key, (Integer) objs[i]);
                    continue;
                }
                if(objs[i] instanceof String){
                    bundle.putString(key, (String) objs[i]);
                    continue;
                }
                if(objs[i] instanceof Boolean){
                    bundle.putBoolean(key, (Boolean) objs[i]);
                    continue;
                }
                if(objs[i] instanceof Serializable){
                    bundle.putSerializable(key, (Serializable) objs[i]);
                    continue;
                }
                if(objs[i] instanceof Parcelable){
                    bundle.putParcelable(key, (Parcelable) objs[i]);
                    continue;
                }
            }
            return bundle;
        }

    使用方法:Util.getBundle("string",true,2);  

    解析端:

    String str = getIntent().getExtras().getString(Uril.bundleKeys.get(0));
    Boolean bool = getIntent().getExtras().getBoolean(Uril.bundleKeys.get(1))
    int num = getIntent().getExtras().getInt(Uril.bundleKeys.get(2))
  • 相关阅读:
    delphi内存管理
    Dbgrid导出为word
    indy传输文件
    TMethod
    http状态码详解
    如何严格设置php中session过期时间
    http和https的优缺点,区别与工作原理
    session的生命周期
    Mysql分库分表方案,如何分,怎样分?
    【观点】程序员应知——循序渐进 狼人:
  • 原文地址:https://www.cnblogs.com/woaixingxing/p/7081154.html
Copyright © 2011-2022 走看看