Intent的使用:显示调用及隐式调用
2016-12-06 16:52
274 查看
package com.zdsoft.launchmode1201; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class AActivity extends AppCompatActivity { private Button bt_zhi, bt_yin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_a); initView(); //Intent调用 bt_zhi.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setClass(AActivity.this, BActivity.class); startActivity(intent); } }); //Intent隐式调用 bt_yin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setPackage("com.zdsoft.launchmode1201"); intent.setAction("com.zhidi.actoin.MAP"); intent.addCategory("android.intent.category.APP_MAPS"); startActivity(intent); } }); } private void initView() { bt_zhi = (Button) findViewById(R.id.bt_zhi); bt_yin = (Button) findViewById(R.id.bt_yin); } }
package com.zdsoft.launchmode1201; 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 { private Button bt_b; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_b); initView(); bt_b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(BActivity.this,CActivity.class); startActivity(intent); } }); } private void initView(){ bt_b= (Button) findViewById(R.id.bt_b); } }
package com.zdsoft.launchmode1201; 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 { private Button bt_c; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_c); initView(); bt_c.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(CActivity.this,AActivity.class); startActivity(intent); } }); } private void initView(){ bt_c= (Button) findViewById(R.id.bt_c); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="A页面" /> <Button android:id="@+id/bt_zhi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="直接调用"/> <Button android:id="@+id/bt_yin" 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" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="B页面" /> <Button android:id="@+id/bt_b" 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" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="C页面" /> <Button android:id="@+id/bt_c" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="完成"/> </LinearLayout>
相关文章推荐
- TextView设置不同的颜色字体
- Nginx+keepalived双机热备(主从模式)
- mongodb高级查询
- MySQL字符集的一个坑
- MySQL字符集的一个坑
- 数据结构与算法2:线性结构与线性表-顺序表
- js事件处理
- 一个优秀的公众号运营者需要具备哪些能力?
- Java多线程学习
- 可等待计时器内核对象的使用(CreateWaitableTimer)
- StopWatch计时器(java小工具)
- 502 bad gateway
- Docker学习笔记八:Swarm
- i2c 驱动四:sysfs文件系统
- [置顶] bootstrap中input添加.form-control类有何作用?
- sap批量创建盘点凭证以及盘点凭证过账
- spring+mybatis报Cannot load JDBC driver class ${xxxxx}'错误
- jeecms怎么修改后台访问路径?
- Android gc垃圾回收研究学习
- SAN环境中WWN,WWNN,WWPN的区别