Intent的使用:显示调用 Activity的跳转
2016-12-06 17:00
351 查看
package com.zdsoft.startactivity1201; import android.content.Intent; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class AActivity extends AppCompatActivity implements View.OnClickListener { private Button bt_b, bt_c; private final int RC_B = 1; private final int RC_C = 2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_a); initView(); initListener(); } private void initView() { bt_b = (Button) findViewById(R.id.bt_b); bt_c = (Button) findViewById(R.id.bt_c); } private void initListener() { bt_b.setOnClickListener(this); bt_c.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bt_b: Intent intent = new Intent(AActivity.this, BActivity.class); startActivityForResult(intent, RC_B); break; case R.id.bt_c: Intent intent1 = new Intent(AActivity.this, CActivity.class); startActivityForResult(intent1, RC_C); break; default: break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RC_B: if (resultCode == RESULT_OK) { Toast.makeText(AActivity.this, data.getStringExtra("txt"), Toast.LENGTH_SHORT).show(); } break; case RC_C: if (resultCode == RESULT_OK) { Toast.makeText(AActivity.this, data.getStringExtra("txt"), Toast.LENGTH_SHORT).show(); } break; default: break; } } }
package com.zdsoft.startactivity1201; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class BActivity extends AppCompatActivity implements View.OnClickListener { private Button bt_b_return; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_b); initView(); initListener(); } private void initView() { bt_b_return = (Button) findViewById(R.id.bt_b_return); } private void initListener() { bt_b_return.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bt_b_return: Intent intent = new Intent(); setResult(RESULT_OK, intent.putExtra("txt", "b页面")); finish(); break; default: break; } } }
package com.zdsoft.startactivity1201; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class CActivity extends AppCompatActivity implements View.OnClickListener { private Button bt_c_return; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_c); initView(); initListener(); } private void initView() { bt_c_return = (Button) findViewById(R.id.bt_c_return); } private void initListener() { bt_c_return.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bt_c_return: Intent intent = new Intent(); setResult(RESULT_OK, intent.putExtra("txt", "c页面")); finish(); break; default: break; } } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <Button android:id="@+id/bt_b" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转B页面" /> <Button android:id="@+id/bt_c" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转C页面" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="b页面" /> <Button android:id="@+id/bt_b_return" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="返回" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="c页面" /> <Button android:id="@+id/bt_c_return" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="返回" /> </LinearLayout>
相关文章推荐
- C++正则表达式的使用
- @Html内的函数解析。(一)
- 第一章 开发简单的java应用程序
- android系统联系人查询流程
- [转载]正高级职称与副高级职称的区别是什么
- C/C++无限关机(提权例子)
- “条件语句”和“循环语句”
- MTK路由器rt5350 mt7620 7688等串口控制台不能修改默认波特率问题
- ubuntu14.04安装OpenJDK1.8
- 浅谈 &0xFF操作
- iOS常用宏 定义
- 【java】java处理中文名字的隐藏(身份证、卡号的隐藏也可以借鉴)
- 11 个重要的数据库设计规则
- 【C#工具类】发送邮件(带有图片和附件)
- JavaScript高级程序设计4--面向对象的程序设计(上)
- 实验11——指针的基础应用
- 关于JDK环境变量的配置问题
- updatepanel用法之triggers使用示例
- 《信息安全系统设计》第四次实验报告
- 11显式实现接口