首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

多个Activity其间的通信

2012-09-20 
多个Activity之间的通信??分界面?string.xml?资源配置文件 androidManifest.xml???? 主Activity?次要的Act

多个Activity之间的通信

?

?分界面

?string.xml

?资源配置文件 androidManifest.xml

?

?

?? 主Activity

?

次要的Activity

package com.file;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;public class otherActivity extends Activity {   private TextView textview;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);//执行构造一个界面setContentView(R.layout.otherui); //执行要使用的界面textview=(TextView)this.findViewById(R.id.result);Intent intent=otherActivity.this.getIntent();//获取传递过来的意图int id=intent.getIntExtra("id", 0); //获取意图传递过来的参数 方法对应的 参数一 参数名 默认的值String name=intent.getStringExtra("name");textview.setText("id为:"+id+",name:"+name);Button button = (Button)this.findViewById(R.id.finish);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent();//数据是使用Intent返回intent.putExtra("result", "itcast student");//把返回数据存入IntentotherActivity.this.setResult(12, intent);//设置返回数据otherActivity.this.finish();}});}}

?

好了 到这里就结束了 看懂了代码就自然懂了

热点排行