重温3 Activity Intent 向下传递数据 向上传递数据
来源:互联网 发布:淘宝网松糕鞋女鞋网的 编辑:程序博客网 时间:2024/05/16 04:54
1、使用Intent向下传递数据
Intent intent = new Intent(MainActivity.this,SecongActivity.class);intent.putExtra("data_from_MainActivity","I am MainActivity");startActivity(intent);从SecondActivity取数据
Intent intent = getIntent();String data = intent.getStringExtra("data_from_MainActivity");根据传递的数据的类型选择getIntExtra()/getBooleanExtra...
2、向上传递数据
MainActivity.java
Intent intent1 = new Intent("sunny.example.comeonintent.ACTION");startActivityForResult(intent1,1);期望返回数据
startActivityForResult()
void android.support.v4.app.FragmentActivity.startActivityForResult(Intent intent, int requestCode)
SubActivity.java
Intent intent = new Intent();intent.putExtra("data_from_sub", "I am Sub");setResult(RESULT_OK,intent);//RESULT_OK -1;RESULT_CANCELED 0;在MainActivity中接收数据
<span style="white-space:pre"></span>@Overrideprotected void onActivityResult(int RequestCode,int ResultCode,Intent data){TextView tv1 = (TextView)findViewById(R.id.tv1);TextView tv2 = (TextView)findViewById(R.id.tv2);switch(RequestCode){case 1:if(ResultCode == RESULT_OK){String returnData1 = data.getStringExtra("data_from_sub");tv1.setText(returnData1);}else{}case 2:if(ResultCode == RESULT_OK){String returnData2 = data.getStringExtra("data_from_third");tv2.setText(returnData2);}else{}default:}}完整代码在:https://github.com/HiSunny/ComeOnIntent.git
0 0
- 重温3 Activity Intent 向下传递数据 向上传递数据
- Intent向下传递数据
- 基础之Intent向下,向上一个活动个传递数据
- Intent 向下一个活动传递数据
- Intent(三)向下一个活动传递数据
- Intent 向下一个活动传递数据
- Intent向下一个活动传递数据putExtra
- Android向上一个Activity传递数据
- android向下一个活动页面传递数据和向上一个页面传递数据
- 用intent在activity间传递数据
- 【intent extra】Android Activity直接传递数据
- 用Intent在Activity间传递数据
- Activity之间的数据传递: Intent
- intent和activity之间传递数据
- 用Intent在Activity之间传递数据
- 使用Intent在activity之间传递数据
- 使用Intent启动Activity传递数据
- Android Activity通过Intent传递数据
- 和为s的两个数字 VS 和为s的连续正数序列42
- 图解unity3d最新最全资源包
- The connection to adb is down, and a severe error has occured问题
- JAVA多线程和并发基础面试问答(转载)
- 【精要主义】软件工程师最重要的素质
- 重温3 Activity Intent 向下传递数据 向上传递数据
- 线程间协作的两种方式:wait、notify、notifyAll和Condition
- C++二级指针和二维数组
- Centos7设置成和公司工作地方一样的192.168.9.xxx网段
- 利用Canvas+js实现贪吃蛇(2)
- Service中通过main方法加载Spring连接数据库等操作
- 第12周 数据结构和算法 线性表-5 栈-栈完成进制转换及应用
- 杭电2053S之Switch Game
- 应用服务器性能优化 之 消息队列(MQ:Message Queue)