安卓Activity中intent传送和接收数据

1.传送数据

@Override
    public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
        /*
         * exameName(考试名称)、 exameType(考试类型)、 durationTime(考试时长)、
         * passScore(及格分数)、 totalScore(总分)、terminalDate(考试截止日期)、
         * isDone(是否已考:0表示未考 1表示已考)
         */
        Map map = data.get(arg2);
        String exameName = map.get("exameName").toString();
        String exameType = map.get("exameType").toString();
        String durationTime = map.get("durationTime").toString();
        String passScore = map.get("passScore").toString();
        String totalScore = map.get("totalScore").toString();
        String terminaldDateStr = map.get("terminalDate").toString();
        String terminalDate = terminaldDateStr.substring(5);
        String isDone = map.get("isDone").toString();
        // id考试的id(examId)
        String examId = map.get("examId").toString();

        Intent intent = new Intent(this, ExamNoticeActivity.class);
        intent.putExtra("exameName", exameName);
        intent.putExtra("exameType", exameType);
        intent.putExtra("durationTime", durationTime);
        intent.putExtra("passScore", passScore);
        intent.putExtra("totalScore", totalScore);
        intent.putExtra("terminalDate", terminalDate);
        intent.putExtra("isDone", isDone);
        intent.putExtra("examId", examId);
        startActivity(intent);

    }

2.接收数据

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        //设置当前的Activity的界面布局   
        setContentView(R.layout.activity_exam_notice);

        //第一种方式
        Bundle bundle = this.getIntent().getExtras();//获得绑定字段      
        isDoneStr=bundle.getString("isDone");//是否已考:0表示未考 1表示已考
        terminalDate=bundle.getString("terminalDate");//截止报考日期
        examId=bundle.getString("examId");//考试id
        System.out.println("考试的id:\n"+examId);//打桩测试
        String exameNameStr=bundle.getString("exameName");//获得"exameName"绑定字段
        exameName1.setText(exameNameStr);//将获取的的字段设置到exameName1处
        exameName2.setText("考试名称:"+exameNameStr);
        exameType.setText("考试类型:"+bundle.getString("exameType"));
        durationTime.setText("考试时长:"+bundle.getString("durationTime")+"分钟");
        passScore.setText("及格分数:"+bundle.getString("passScore")+"分");
        totalScore.setText("考试总分:"+bundle.getString("passScore")+"分");


        //第二种方式
        /*
        //获得Intent
        Intent intent = this.getIntent();            
        //从Intent获得额外信息,设置为TextView的文本   
        exameName1.setText(intent.getStringExtra("exameName"));   
        exameName2.setText(intent.getStringExtra("exameName")); 
         */
    }

你可能感兴趣的:(intent传收数据)