• 显示或者隐式


    1.显式启动
    Intent intent = new Intent(this, class);
    startActivity(intent);

    2.隐式启动
    AndroidManifest.xml中定义某个Activity的intent-fliter
    <intent-filter>
    <action android:name="com.example.activity.ACTION_START" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="com.example.activity.ACTION_START" />
    </intent-filter>

    Activity中
    Intent intent = new Intent("com.example.activity.ACTION_START");
    //android.intent.category.DEFAULT是一种默认的category,在startActivity时自动添加
    intent.addCategory("com.example.activity.ACTION_START"); 
    startActivity(intent);
    隐式启动,在启动的时候是不明确的,需要匹配系统或AndroidManifest.xml中的intent-filter定义,只有action和category和data完全匹配时,才会启动.


    隐式启动不仅可以启动自己的Activity,还可以启动其他的Activity,如打开网页
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://www.baidu.com"));
    startActivity(intent);

    这儿首先指定了intent的action为Intent.ACTION_VIEW,这是android内置的打开网页动作,然后通过Uri.parse将一个网址解析为Uri对象,再调用Intent的setData将Uri对象传递进去.

    转载:https://www.cnblogs.com/itfenqing/p/6714985.html

  • 相关阅读:
    CSharp程序员学Android开发---1.初识AndriodIDE,掌握工具使用
    生产者-消费者问题(2)
    c++顺序容器
    打印二叉树某一层次的值(重点)
    二叉树层次遍历
    搜索算法比较
    动态定义数组
    RMQ(range minimum/maximum query)即查询区间最大最小值。
    string 空值
    vector 下标操作
  • 原文地址:https://www.cnblogs.com/BlueFire-py/p/8612704.html
Copyright © 2020-2023  润新知