zoukankan      html  css  js  c++  java
  • intent使用Serializable传递对象

    package com.pingyijinren.test;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    
    public class IndexActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_index);
    
            Intent intent=new Intent(this,TransferObjectActivity.class);
            Person person=new Person();
            person.setAge(26);
            person.setName("张钦雄");
            intent.putExtra("person",person);
            startActivity(intent);
        }
    }
    package com.pingyijinren.test;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    
    public class TransferObjectActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_transfer_object);
    
            Person person=(Person)getIntent().getSerializableExtra("person");
            Log.d("MainActivity",person.getName()+" "+person.getAge());
        }
    }
    package com.pingyijinren.test;
    
    import java.io.Serializable;
    
    /**
     * Created by Administrator on 2016/5/20 0020.
     */
    public class Person implements Serializable{
        private String name;
        private int age;
    
        public void setName(String name){
            this.name=name;
        }
    
        public void setAge(int age){
            this.age=age;
        }
    
        public String getName(){
            return name;
        }
    
        public int getAge(){
            return age;
        }
    }
  • 相关阅读:
    vue 对css样式进行修改
    vue之绑定数据+data、methods、computed、watch的基础用法
    vue安装 devtools失败的临时解决办法
    解决VMware Workstation 与 Device/Credential Guard 不兼容
    后渗透之meterpreter常用命令
    2020-7- 27
    PIL模块调整图片大小
    maven(一) maven到底是个啥玩意~
    noi前第十二场 题解
    noi前第十一场 题解
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5511589.html
Copyright © 2011-2022 走看看