码迷,mamicode.com
首页 > 移动开发 > 详细

Android Activity之间通信

时间:2014-09-17 21:58:32      阅读:333      评论:0      收藏:0      [点我收藏+]

标签:android   os   java   ar   art   cti   log   on   c   

package com.example.myapp;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MyActivity extends Activity {

    private Button btnOk = null;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btnOk = (Button)findViewById(R.id.btnCallOther);
        btnOk.setOnClickListener(new MyButtonListener());

    }

    class MyButtonListener implements View.OnClickListener {


        @Override
        public void onClick(View view) {
            Intent intent = new Intent();

            intent.putExtra("key","value");

            intent.setClass(MyActivity.this,otherActivity.class);

            MyActivity.this.startActivity(intent);
        }
    }
}

package com.example.myapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

/**
 * Created by chang on 14-9-17.
 */
public class otherActivity extends Activity{
    private TextView tv = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.other);

        Intent intent = getIntent();

        String s = intent.getStringExtra("key");

        tv = (TextView)findViewById(R.id.otherTextView);
        tv.setText(s);
    }
}

Android Activity之间通信

标签:android   os   java   ar   art   cti   log   on   c   

原文地址:http://blog.csdn.net/haifengzhilian/article/details/39347581

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!