Activity之间的跳转分为隐式意图和显示意图。

1.显示意图

显示意图通过构造Intent方法来实现,需要传递两个参数,一个是当前的Activity对象,另一个是要启动的Activity对象。

代码如下:

Intent intent = new Intent(Activity.this,Activity2.class);//创建Intent对象
startActivity(intent);//开启Activity2

2.隐式意图

隐式意图有setAction()、setData()、setCategory()方法,这些方法在使用时都需要在清单文件AndroidManifest中,为Activity添加<intent-filter>标签.

setAction()设置Activity开启动作

java文件中

 Intent intent = new Intent();intent.setAction("cn.itcast.START_ACTIVITY");startActivity(intent); 

AndroidManifest文件中

<intent-filter><action android:name="cn.itcast.START_ACTIVITY"/><category android:name="android.intent.category.DEFAULT"/></intent-filter>

setData()

data属性用来指定数据的URI或者数据MIME类型 。隐式Intent携带的data数据只要与IntentFilter中的任意一个data声明相同,data属性就匹配成功。

<intent-filter><data android:mimeType="video/mpeg" android:scheme="http......" /><data android:mimeType="audio/mpeg" android:scheme="http......" />......
</intent-filter>

setCatagory()

category属性用于为action添加额外信息,一个IntentFilter可以不声明category属性,也可以声明多个category属性。

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

简单实例代码——在ADV中打开百度界面

activity_main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/img"android:orientation="horizontal"><Buttonandroid:id="@+id/btn_baidu"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="15dp"android:layout_centerInParent="true"android:text="百度"android:textSize="20sp"/></RelativeLayout>

MainActivity.java文件

package com.example.openbrowser;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button1 = (Button) findViewById(R.id.btn_baidu);button1.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Intent intent = new Intent();intent.setAction("android.intent.action.VIEW");intent.setData(Uri.parse("http://baidu.com"));startActivity(intent);}});}
}

AndroidManifest.xml文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.openbrowser"><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.OpenBrowser"><activityandroid:name=".MainActivity"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><action android:name="android.intent.action.VIEW" /><data android:mimeType="video/mpeg" android:scheme="http://baidu.com" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>

 

Android开发之隐示意图跳转相关推荐

  1. android之隐示意图跳转启动另一个activity

    主面板布局:layout/activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...

  2. Android旋转视频工具类,Android开发实现的IntentUtil跳转多功能工具类【包含视频、音频、图片、摄像头等操作功能】...

    本文实例讲述了Android开发实现的IntentUtil跳转多功能工具类.分享给大家供大家参考,具体如下: 说明:此工具类是本人开发中总结下来的,还有其它的跳转亲给我留言,希望大家一起把这个工具类打 ...

  3. android 华为开发权限管理,android开发 华为 点击跳转到权限管理页面

    private void goHuaWeiSetting()  { try { //HUAWEI H60-l02 P8max测试通过 Log.d(MainActivity.class.getSimpl ...

  4. Android开发10——Activity的跳转与传值

    Activity跳转与传值,主要是通过Intent类,Intent的作用是激活组件和附带数据. 一.Activity跳转 方法一 Intent intent = new Intent(A.this,B ...

  5. Android开发-实现第三方APP跳转

    自己创建一个按钮: <Button android:id="@+id/btn_button" android:layout_width="fill_parent&q ...

  6. Android开发添加QQ群 跳到QQ聊天页面

    /**************** * * 发起添加群流程.群号:001(527210803) 的 key 为: 1M5ETlWF976e98HWlsVFDj4cdJKwAnoK * 调用 joinQ ...

  7. Android开发-小技巧汇总2

    启动虚拟机时,在 launch options 窗口中 有个 wipe user data ,勾选它,将会让虚拟机 [恢复出厂设置] 2.[如果想让自己的应用程序有多个启动图标:] 为一个应用的 多个 ...

  8. Intent 隐示意图

    1.从google搜索内容  Intent intent = new Intent();  intent.setAction(Intent.ACTION_WEB_SEARCH);  intent.pu ...

  9. Android开发,你所不知道的Android原生开发的现状

    此外还有许多针对Android的非关系型的数据库,例如Realm,Parse,Firebase,ObjectBox等(其中有些仍在使用SQLite).如果我没记错的话,它们中的大多数(甚至全部)都具有 ...

  10. Android 隐式跳转(Activity的隐式跳转)

    学而时习之,温故而知新,放假前回顾下android 的 隐式跳转 Activity的显式跳转: 是直接指定需要调用的Activity Activity的隐式跳转: 不明确指定启动哪个Activity, ...

最新文章

  1. jquery autocomplete demo
  2. EXCEL如何验证重复数据?
  3. 从零开始来看一下Java泛型的设计
  4. 小程序实践(三):九宫格实现及item跳转
  5. JS之颠倒数组元素的reverse方法
  6. 如何和后台接触的_后台产品,不只是做支持
  7. SAP系统中资产的分类规则
  8. 解决Android Studio连接不到ios模拟器问题
  9. talemu---蒙特卡洛仿真软件产品介绍
  10. 软件设计师真题知识点
  11. ARM(ARM处理器) x64和x86
  12. [转] Linux-2.6.32 NUMA架构之内存和调度
  13. 人生如逆旅,我亦是行人——与余光中先生握一次手(二)
  14. 回归云平台的本质,通过平台+应用模式实现软件资源线上共享
  15. 书论83 梁巘《承晋斋积闻录》
  16. 面料ERP_面料企业ERP管理系统_面料软件
  17. python网格交易法详解_给大家科普一下网格交易法
  18. SybilFuse:Combining Local Attributes with Global Structure to Perform Robust Sybil Detect(论文笔记)
  19. 使用acmesh免费开启https(详细概念介绍与操作步骤记录)
  20. 公司裁员不想给补偿,竟然耍这些不要脸的裁员手段..

热门文章

  1. 毕索大学计算机科学怎么样,毕索大学与麦吉尔大学哪个好
  2. stata回归分析与系数检验专题【计量经济系列(三)】
  3. 这个开源的去马赛克神器 修复受损漫画无压力
  4. 计算机启动死机,电脑开机突然死机怎么回事?小编教你解决开机死机问题
  5. 海贼王热血航线正在连接服务器,海贼王热血航线为什么连接不了服务器?老是说人已满进不去?...
  6. Photoshop抠图(运用背景橡皮擦工具进行抠图)
  7. 性能优化,进无止境---内存篇(上)
  8. android 屏幕分辨率获取,Android获取屏幕分辨率的三种方法
  9. 99%的人都不知道的减肥小秘密,你必须知道
  10. 彪悍的人生不需要解释!