Android Activity之间通信
2015-12-29 10:46
423 查看
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中ActionBar中setDisplayHomeAsUpEnabled和setHomeButtonEnabled和setDisplayShowHomeEnabled方法的理解
- android 自定义动画2
- Android版添加phonegap--imagePicker插件教程
- Android 快速开发系列 ORMLite 框架最佳实践
- Android 自定义Animation动画
- android Toast、Looper、Handler消息循环机制
- Android遇到的问题总结
- Android调试时每次弹出Android Device Chooser窗口
- Android 使用NineOldAndroids实现绚丽的ListView左右滑动删除Item效果
- android中修改tablayout中的字体大小和颜色
- Android-Text and Input
- Android界面设计视觉规范(转)
- Android开发总结笔记 Btimap (下) 3-5
- android 开发问题汇总持续
- Android 下获取所有应用的流量使用量
- 报错:Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
- Android代码里判断语言和横竖屏
- Android动态渐变view的颜色
- Android中以JAR形式封装控件或者类库
- Android屏幕适配