显示意图,一般情况下是用于,APP应用自身:组件(Activity,Service,...) 与 组件(Activity,Service,...) 的激活调用:

显示意图,是可以看得到,明确激活哪一个Activity

package liudeli.activity.intent;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View; import liudeli.activity.R; public class OneActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_one);
} public void startTwoActivity(View view) {
/**
* 显示意图激活的三种方式
*/
// 1.快捷方式激活
// Intent intent = new Intent(this, TwoActivity.class); // 2.面向组件激活,老外很喜欢用这种方式激活
/*Intent intent = new Intent();
ComponentName componentName = new ComponentName(this, TwoActivity.class);
intent.setComponent(componentName);*/ // 3.设置Class方式激活
/*Intent intent = new Intent();
intent.setClass(this, TwoActivity.class);*/ // 4.设置ClassName方式激活,传入完整包名+类名
Intent intent = new Intent();
intent.setClassName(this, "liudeli.activity.intent.TwoActivity"); startActivity(intent);
} @Override
protected void onDestroy() {
super.onDestroy();
}
}

activity_one.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"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="激活"
android:onClick="startTwoActivity"
/> </RelativeLayout>

隐式意图,隐式意图一般情况下用于,两个应用程序的:组件(Activity,Service,...) 与 组件(Activity,Service,...) 的激活调用:

OuterProject应用的MainActivity需要对外暴露(在AndroidManifest.xml 文件中 对Activity 配置 Intent-filter):

必须要有动作标识:wo.shi.outer.project.main.activity.action
必须要有一个缺省:<category android:name="android.intent.category.LAUNCHER" />
    <activity android:name=".MainActivity">

            <intent-filter>

                <action android:name="wo.shi.outer.project.main.activity.action" />

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

            </intent-filter>

        </activity>

我的应用的OneActivity去隐式意图激活,OuterProject应用的MainActivity

在这里为什么不需要设置:category android:name="android.intent.category.DEFAULT",因为在startActivity会自动添加
    /**
* 隐士意图去激活 OuterProject应用的Activity
*
/*
<intent-filter> <action android:name="wo.shi.outer.project.main.activity.action" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
*/
Intent intent = new Intent();
intent.setAction("wo.shi.outer.project.main.activity.action");
intent.setPackage("liudeli.outer");
// 在这里为什么不需要设置:category android:name="android.intent.category.DEFAULT",因为在startActivity会自动添加
startActivity(intent);

OuterProject应用的MainActivity

Intent-filter 参数增加:

     <!--
android:mimeType="aa/bb" 必须是 xxx/xxx 这种格式,否则安装应用的时候解析失败
android:scheme="mydata" 不需要 mydata:, 但是在激活的那边需要加:
-->
<activity android:name=".MainActivity"> <intent-filter> <action android:name="wo.shi.outer.project.main.activity.action" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="mydata" android:mimeType="aa/bb" /> </intent-filter> </activity>

我的应用的OneActivity去隐式意图激活

    /**
* 隐士意图去激活 OuterProject应用的Activity
*/
/*
<intent-filter> <action android:name="wo.shi.outer.project.main.activity.action" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="mydata" android:mimeType="aa/bb" /> </intent-filter>
*/
Intent intent = new Intent();
intent.setAction("wo.shi.outer.project.main.activity.action");
intent.setPackage("liudeli.outer"); // 注意⚠️:当有Data和Type的时候,这种方式不可用

Android-显示意图和隐式意图的更多相关文章

  1. Android学习记录(7)—Intent中显示意图和隐式意图的用法

    Intent(意图)主要是解决Android应用的各项组件之间的通讯. Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到对应的 ...

  2. Android 显示意图和隐式意图的区别

    意图在android的应用开发中是很重要的,明白了意图的作用和使用后,对开发会有很大帮助.如果没有把意图搞懂,以后开发应用会感觉缺些什么.        意图的作用:        1.激活组件   ...

  3. 基础学习总结(八)--Intent中显示意图和隐式意图的用法

    Intent(意图)主要是解决Android应用的各项组件之间的通讯.Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到对应的组 ...

  4. Android的显示意图和隐式意图总结

    显示意图 简而言之: 通过指定特定Activity的包名和类名开启Activity 应用场景: 一般应用于本App内的activity间的跳转. XML配置信息: AndroidManifest.xm ...

  5. Android中显式意图和隐式意图的区别

    1.显式意图 可以直接通过名称开启指定的目标组件: 通过构造方法Intent(Context packageContext,class<?>cls)来实现. button_1 = (But ...

  6. Activity组件:(一)通过显式意图和隐式意图来实现Activity间的跳转

    一.通过显式意图来实现Activity间的跳转 显式意图是指在创建Intent对象时就指定接受者组件 /** * 下面是通过显式意图进行跳转,即明确写出要跳转到SecondActivity.class ...

  7. Activity组件(二):通过显式意图和隐式意图来跳转至第三方应用

    一.显式意图来跳转到第三方应用 /** * 这个方法会在点击按钮的时候执行 * @param view */ public void skip2Browser(View view){ Log.d(TA ...

  8. android intent 隐式意图和显示意图(activity跳转)

    android中的意图有显示意图和隐式意图两种, 显示意图要求必须知道被激活组件的包和class 隐式意图只需要知道跳转activity的动作和数据,就可以激活对应的组件 A 主activity  B ...

  9. 无废话Android之smartimageview使用、android多线程下载、显式意图激活另外一个activity,检查网络是否可用定位到网络的位置、隐式意图激活另外一个activity、隐式意图的配置,自定义隐式意图、在不同activity之间数据传递(5)

    1.smartimageview使用 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...

  10. Android学习笔记_17_Intent匹配规则(隐式意图)

    Android基本的设计理念是鼓励减少组件间的耦合,因此Android提供了Intent (意图) ,Intent提供了一种通用的消息系统,它允许在你的应用程序与其它的应用程序间传递Intent来执行 ...

随机推荐

  1. php call_user_func_array

    call_user_func_array (PHP >= , PHP , PHP ) call_user_func_array — 调用回调函数,并把一个数组参数作为回调函数的参数 说明 mix ...

  2. Rhythmk 一步一步学 JAVA(7): jsp 自定义标签

    1.实现Tag接口: TagSupport类实现了Tag接口,为我们提供了4个重要的方法(见表6-5). 1.1. TagSupport类中的常用方法           int doStartTag ...

  3. Django中多种重定向方法使用

    本文主要讲解使用HttpResponseRedirect.redirect.reverse以及配置文件中配置URL等重定向方法 本文使用了Django1.8.2 使用场景,例如在表单一中提交数据后,需 ...

  4. 使用net.sf.fjep.fatjar插件将第三方JAR包打包进自已的JAR包中

    一般单个工程,在没有应用别人的jar包时导出为jar很简单,只要设置一个Main-Class就行了,也就是选择程序入口(main所在类).但是涉及到了数据库或需要用到第三方的JAR,就需要用到相应的数 ...

  5. 阿里巴巴Java开发规约扫描插件-Alibaba Java Coding Guidelines 在idea上安装使用教程

    经过247天的持续研发,阿里巴巴于10月14日在杭州云栖大会上,正式发布众所期待的<阿里巴巴Java开发规约>扫描插件!该插件由阿里巴巴P3C项目组研发.P3C是世界知名的反潜机,专门对付 ...

  6. Callable接口使用以及计算斐波那契数字的数值总和

    一.简单使用 Runnable是执行工作的独立任务,但是它不返回任何值.如果你希望任务完成的时能够返回一个值,那么可以实现一个Callable接口.在Java SE5中引入的Callable是一种具有 ...

  7. JSP的原理、JSP的执行过程

    Jsp的本质是servlet, 通过response的printWriter返回,response的getOutputStream只能调用一次,返回流就不能返回页面刷新. JSP起源 在很多动态网页中 ...

  8. Nginx源码完全注释(8)ngx_errno.c

    errno.h中的strerror(int errno)可以确定指定的errno的错误的提示信息.在 Nginx 中,将所有错误提示信息预先存储在一个数组里,而预先确定这个数组的大小,是在自动化脚本中 ...

  9. 125. Valid Palindrome (Array; Two-Pointers)

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  10. validator 参数校验的常用注解

    @AssertFalse Boolean,boolean 验证注解的元素值是false @AssertTrue Boolean,boolean 验证注解的元素值是true @NotNull 任意类型 ...