Intent属性,Category属性,直接Intent,间接Intent

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
直接Intent

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10pt"
        android:text="直接Intent"
        android:textAllCaps="false"
        android:onClick="directIntent"
        />

后台代码

    /**
     * 直接Intent按钮的事件处理函数
     * @param v
     */
    public void directIntent(View v){
//        //方法1
//        Intent intent = new Intent(this,JumpActivity.class);
//        startActivity(intent);
//        //方法2
//        Intent intent = new Intent();
//        intent.setClass(this,JumpActivity.class);
//        startActivity(intent);
        //方法3
        Intent intent = new Intent();
        构造目标组件的name
        ComponentName name = new ComponentName(this,JumpActivity.class);
        //设置组件
        intent.setComponent(name);
        startActivity(intent);
    }

间接Intent
先在清单文件中进行匹配,找到画面进行跳转

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10pt"
        android:text="间接Intent"
        android:textAllCaps="false"
        android:onClick="indirectIntent"
        />

后台代码
清单文件中
<intent-filter:过滤器
action:画面的action,是它的动作
category:分类
action与category必须同时使用

        <activity android:name=".JumpActivity">
            <intent-filter>
                <action android:name="lesson10.computer.lession17.jump"/>

                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

主函数Main中

    /**
     * 间接Intent按钮的事件处理函数
     * @param v
     */
    public  void indirectIntent(View v){
        Intent intent = new Intent();
        intent.setAction("lesson10.computer.lession17.jump");
        startActivity(intent);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值