• Android——Intent(意图)


    //Intent的属性
    Intent in1 = new Intent();

    ComponentName componentName = new ComponentName(this,Activity2.class);

    in1.setComponent(componentName);//设置显示意图

    in1.setAction(Intent.ACTION_DIAL);//用特别的字符串规定一些功能的Activity 实现隐式意图 唯一性

    in1.addFlags(1);//自己规定标记 多个

    in1.addCategory("");//多个

    //in1.setDataAndTypeAndNormalize();Type

    Intent intent = new Intent(this,Activity2.class);

    main_layout.xml

    <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="隐式意图调用"
            android:textSize="30dp"
            android:onClick="onclick5"
    
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="隐式意图调用打电话"
            android:textSize="30dp"
            android:onClick="onclick6"
    
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="隐式意图直接拨打电话"
            android:textSize="30dp"
            android:onClick="onclick7"
    
            />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="回到桌面"
            android:textSize="30dp"
            android:onClick="onclick8"
    
            />

    MainActivity.java

    //隐式意图的监听
           public void onclick5(View view)
        {
            //只有action的隐式意图
            Intent intent = new Intent("hello");
    
            startActivity(intent);
        }
        public void onclick6(View view)
        {
            //action的隐式意图
            //传数据  data Uri
            Uri uri = Uri.parse("tel:110");
    
            Intent intent = new Intent(Intent.ACTION_DIAL,uri);
    
            startActivity(intent);
        }
        public void onclick7(View view)
        {
            //action的隐式意图
            //传数据  data Uri
            Uri uri = Uri.parse("tel:110");
    
            Intent intent = new Intent(Intent.ACTION_CALL,uri);
    
            startActivity(intent);
        }
        public void onclick8(View view)
        {
            //action的隐式意图
    
            //回到桌面
            Intent intent = new Intent(Intent.ACTION_MAIN);
    
            intent.addCategory(Intent.CATEGORY_HOME);
    
            startActivity(intent);
        }

    AndroidManifext.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.chenshuai.test321">
    
        <uses-permission android:name="android.permission.CALL_PHONE" />
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="测试"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
    
            <activity android:name=".MainActivity"
                android:launchMode="standard">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".Activity2">
                <intent-filter>
                    <action android:name="hello" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
            <activity android:name=".Activity3">
                <intent-filter>
                    <action android:name="hello" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>

     效果

  • 相关阅读:
    数学思想方法-python计算战(8)-机器视觉-二值化
    04-05组合问题_算法训练
    至HDFS附加内容
    HDU 1010 Tempter of the Bone heuristic 修剪
    二叉树3种遍历的非递归算法
    [Ramda] R.project -- Select a Subset of Properties from a Collection of Objects in Ramda
    [Ramda] Refactor a Promise Chain to Function Composition using Ramda
    [SVG] Combine Multiple SVGs into an SVG Sprite
    [Ramda] Difference between R.converge and R.useWith
    [Ramda] Refactor to a Point Free Function with Ramda's useWith Function
  • 原文地址:https://www.cnblogs.com/Chenshuai7/p/5306832.html
Copyright © 2020-2023  润新知