zoukankan      html  css  js  c++  java
  • Android之Parcelable使用

    必须实现Parcelable:且属性的writeXXX与readXXX必须顺序一一对应

    public class BaseModel implements Parcelable {
    
        public long mID;
    
        public long getmID() {
            return mID;
        }
    
        public void setmID(long mID) {
            this.mID = mID;
        }
    
        @Override
        public int describeContents() {
            // TODO Auto-generated method stub
            return 0;
        }
    
        @Override
        public void writeToParcel(Parcel dest, int flags) {
            // TODO Auto-generated method stub
             dest.writeLong(mID); 
        }
    
        public static final Parcelable.Creator<BaseModel> CREATOR = new Parcelable.Creator<BaseModel>() {   
            //重写Creator
              
                    @Override  
                    public BaseModel createFromParcel(Parcel source) {   
                        BaseModel p = new BaseModel();   
                        p.mID = source.readLong(); 
                        return p;   
                    }   
              
                    @Override  
                    public BaseModel[] newArray(int size) {   
                        // TODO Auto-generated method stub   
                        return new BaseModel[size];  
                    }   
                };   
              
        
        
    }


    发送广播:

    public static void sendList(Context mContext,ArrayList<MusicModel> list){
            Intent intent = new Intent("PLAYLIST");
            
            intent.putParcelableArrayListExtra(MediaService.MediaServicePlayList, list);
            
            mContext.sendBroadcast(intent);
        }


    接收广播:

    public class PlayListReceiver extends BroadcastReceiver{
    
            @Override
            public void onReceive(Context context, Intent intent) {
                
                mList = intent.getParcelableArrayListExtra(MediaServicePlayList);
                
            }
            
        }


    注册广播:

    playListReceiver = new PlayListReceiver();
            registerReceiver(playListReceiver,new IntentFilter("PLAYLIST"));
  • 相关阅读:
    求自变量的取值范围时需要注意的角度
    求正弦型函数的解析式
    求三角形面积的最值[范围]
    三角函数对称性[奇偶性]
    2019届高三理科数学选择填空整理
    均值不等式使用变化
    破解正弦型函数参数的取值范围
    构造法求数列通项公式
    累乘法
    Centos中压缩(zip)和解压(unzip)命令
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/2943320.html
Copyright © 2011-2022 走看看