• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            life02

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              197 隨筆 :: 3 文章 :: 37 評論 :: 0 Trackbacks
            android 中通過 aidl 傳遞map對象
            http://blog.sina.com.cn/s/blog_7a4b93580100um3s.html
                分類: android
            思路: aidl傳遞
            -------intent(包含一個bundle對象而bundle中放的是Bundle.putSerializable(String key, Serializable value))--------Serializable value(這里我想放的是一個map對象)-----HashMap(Map<String, ArrayList<Entity>>  String為這個數(shù)據(jù)集合的一個標(biāo)記可以通過這個標(biāo)記獲取這個數(shù)據(jù)集合)---- ArrayList<Entity> (實(shí)體的數(shù)據(jù)集合類)。

            雜癥:Serializable value
            實(shí)體Entity實(shí)現(xiàn)了序列化接口,依然不可傳遞。解決辦法是將map封裝了一下,實(shí)現(xiàn)了序列化接口就OK了。

            實(shí)例:某哥們的demo(用了兩個Activity,一個傳遞數(shù)據(jù),另一個接受數(shù)據(jù)):

            封裝的map:

            public class MyMap implements Serializable{



                
            private Map<String, ArrayList<Entity>> map;



                
            public Map<String, ArrayList<Entity>> getMap() {

                    
            return map;

                }



                
            public void setMap(Map<String, ArrayList<Entity>> map) {

                    
            this.map = map;

                }

                

            }

            實(shí)體Entity:

              

            public class Entity implements Serializable{

              String id;

              String name;

              String age;

                
            public String getId() {

                    
            return id;

                }

                
            public void setId(String id) {

                    
            this.id = id;

                }

                
            public String getName() {

                    
            return name;

                }

                
            public void setName(String name) {

                    
            this.name = name;

                }

                
            public String getAge() {

                    
            return age;

                }

                
            public void setAge(String age) {

                    
            this.age = age;

                }

                  

            }

             用于傳遞數(shù)據(jù)的Activity:

            public class MapDemoActivity extends Activity {

                Button button;

                

                @Override

                
            public void onCreate(Bundle savedInstanceState) {

                    
            super.onCreate(savedInstanceState);

                    setContentView(R.layout.main);

                    

                    Map
            <String, ArrayList<Entity>> map=initData();

                    
            final MyMap myMap=new MyMap();

                    
            //將map數(shù)據(jù)添加到封裝的map中
                    myMap.setMap(map);

                    

                    button
            =(Button) findViewById(R.id.btn);

                    button.setOnClickListener(
            new OnClickListener() {

                        

                        
            public void onClick(View v) {

                            
            // TODO Auto-generated method stub
                            Intent intent=new Intent(MapDemoActivity.this,ReceiveMap.class);

                            Bundle bundle
            =new Bundle();

                            bundle.putSerializable(
            "map", myMap);

                            intent.putExtras(bundle);

                            startActivity(intent);

                        }

                    });

                }

                

                
            private Map<String, ArrayList<Entity>> initData() {

                    
            // TODO Auto-generated method stub
                    Map<String, ArrayList<Entity>> map=new HashMap<String, ArrayList<Entity>>();

                      
            for(int i=0;i<10;i++){

                        ArrayList
            <Entity> list=new ArrayList<Entity>();

                          
            for(int j=0;j<10;j++){

                              Entity entity
            =new Entity();

                              entity.setId(
            ""+j);

                              entity.setName(
            "name"+j);

                              entity.setAge(
            "age"+j);

                              list.add(entity);

                          }

                          map.put(
            "path"+i, list);

                      }

                    
            return map;

                }

                

                

            }

              

            用來接受數(shù)據(jù)的Activity:

            public class ReceiveMap extends Activity {

                TextView textView;

                Button  button;

                MyMap myMap;

                
            protected void onCreate(Bundle savedInstanceState) {

                    
            // TODO Auto-generated method stub
                    super.onCreate(savedInstanceState);

                    setContentView(R.layout.receive_data);

                    

                    Bundle bundle
            =getIntent().getExtras();

                    myMap
            =(MyMap) bundle.get("map");

                    

                    textView
            =(TextView) findViewById(R.id.tv);

                    button
            =(Button) findViewById(R.id.receive_btn);

                    button.setOnClickListener(
            new OnClickListener() {

                        

                        
            public void onClick(View v) {

                            
            // TODO Auto-generated method stub
                            Map<String, ArrayList<Entity>> map=myMap.getMap();

                            
            if(map==null)

                                
            return ;

                            
            for(int i=0;i<10;i++){

                                ArrayList
            <Entity> list=map.get("path"+i);

                                
            if(list==null||list.size()==0)

                                    
            continue;

                                    textView.append(
            "map key--"+"path"+i+"---list size is---"+list.size()+"\n");

                            }

                        }

                    });

                }

               

            }

            posted on 2012-04-06 14:08 life02 閱讀(4157) 評論(0)  編輯 收藏 引用 所屬分類: Android開發(fā)
            国产精品久久久久久五月尺| 91精品国产综合久久久久久| 2020最新久久久视精品爱| 久久午夜福利无码1000合集| 久久久久亚洲精品天堂久久久久久| 国产成人精品免费久久久久| 精品多毛少妇人妻AV免费久久| 日产久久强奸免费的看| 国产—久久香蕉国产线看观看| 日本久久久久久中文字幕| 精品久久久无码人妻中文字幕豆芽 | 大香伊人久久精品一区二区| 欧美性猛交xxxx免费看久久久| 亚洲国产成人久久笫一页| 亚洲国产成人久久一区久久| 亚洲午夜精品久久久久久浪潮 | 久久久久无码精品| 久久久久久噜噜精品免费直播| 久久这里的只有是精品23| 无码AV中文字幕久久专区| 久久国产精品国产自线拍免费| A级毛片无码久久精品免费| 热RE99久久精品国产66热| 亚洲国产一成人久久精品| 久久精品一本到99热免费| 亚洲午夜久久影院| 一本久道久久综合狠狠躁AV| 午夜人妻久久久久久久久| 91精品国产高清久久久久久国产嫩草 | 青青久久精品国产免费看| 日韩久久久久久中文人妻| 久久AⅤ人妻少妇嫩草影院| 精品久久久久久久国产潘金莲 | 日产久久强奸免费的看| 麻豆一区二区99久久久久| 国产一区二区三精品久久久无广告| 香蕉久久久久久狠狠色| 青青青国产成人久久111网站| 久久精品极品盛宴观看| 国产精品久久久99| 久久久久久国产精品免费无码|