一、Activity启动和结束
当前页面跳到新页面
startActivity(new Intent(源页面.this,目标页面.class);
从当前页面回到上一个页面
finish();
主界面用singleTask
Activity启动模式
两个Activity之间跳转
二、Intent
intent:意图,是各个组件之间信息沟通的桥梁,用于Android各组件之间的通信
标明通信从哪来到哪去,要怎么走
发起方携带本次通信需要的数据,接收方从收到的意图中解析数据
发起方若想判断接收方的处理结果,意图要负责让接收方传回应答的数据内容
1、在Intent的构造函数中指定
Intent intent=new Intent(this,Activity.class);//创建一个目标确定的意图
2、调用意图对象的setClass方法指定
Intent intent=new Intent();
intent.setClass(this,Activity.class);
3、调用意图对象的setComponent方法指定
Intent intent=new Intent();
//创建包含目标活动在内的组件名称对象
ComponentName component=new ComponentName(this,Activity.class);
intent.setComponent(component);//设置意图携带的组件信息
三、向下一个activity发送数据
Bundle
在代码中发送消息包裹,调用意图对象的putExtras方法,即可存进消息包裹。
在代码中接收消息包裹,调用意图对象的getExtras方法,即可取出消息包裹。
四、利用资源文件配置字符串
五、利用元数据传递配置信息
先在AndroidManifest中放置信息
在用第三方sdk时比较常用,整合开发包
六、给应用页面注册快捷方式
元数据还能传送更复杂的资源数据,比如支付宝的快捷方式菜单
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut android:shortcutId="first"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/first"
android:shortcutLongLabel="@string/first"
>
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example.chapter04"
android:targetClass="com.example.chapter04.ActionUriActivity">
</intent>
<categories>
android:name="android.shortcut.conversation"
</categories>
</shortcut>
<shortcut android:shortcutId="second"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/second"
android:shortcutLongLabel="@string/second">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example.chapter04"
android:targetClass="com.example.chapter04.ActSendActivity">
</intent>
<categories>
android:name="android.shortcut.conversation"
</categories>
</shortcut>
</shortcuts>
1、enabled:表示当前快捷方式是否可使用
2、 icon: 快捷方式图标
3、 shortcutDisabledMessage: 快捷方式不可使用时显示的名字
4、 shortcutId:快捷方式标识
5、 shortcutLongLabel:长按下图标弹出来列表框中每个快捷名
6、 shortcutShortLabel:快捷是可以单独显示在桌面上的,显示名为shortcutShortLabel
7、 targetClass:点击快捷方式进入的Activity
8、categories 默认写死即可
注意,shortcutLongLabel和shortcutShortLabel,不可以直接引用文字