zoukankan      html  css  js  c++  java
  • Android Intent的花样启动

    刚开始看郭大神的<<第一行代码>>,实现以下里面的一些例子.Intent的花样启动

    1. 显示Intent的使用.

      实例化一个Intent,并且制定当前的activity和要跳转到的activity

          Intent intent=new Intent(MainActivity.this,TwoActivity.class
      				);
      	startActivity(intent);
      

    2.隐式Intent的使用.

    1. 我们首先需要在项目的AndroidManifest.xml里面要的activity标签里面添加一个intent-filter标签,并指定它们的action,category,当然你也可以指定它的data.

      关于data的一些说明

    • android:scheme
      用于指定数据的协议部分,如http/https.

    • android:host
      用于指定数据的主机名部分,如www.google.com/

    • android:port
      用于指定主机名和端口之后的部分,如一段网址中跟在域名后面的内容.

    • android:mineType
      用于指定可以处理的数据类型,允许使用通配符的方式进行指定.

    注.只有data标签中指定的内容和Intent中携带的Data完全一致时,当前的活动才能响应该Intent.

        <activity 
                android:name="com.example.menu.Activity"
                >
                <intent-filter>
                    <action android:name="com.example.Menu.ACTION_START"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
            </activity>
    
    Intent intent=new Intent("com.example.Menu.ACTION_START");
    			startActivity(intent);
    

    其实你还可以这样.

        Intent intent=new Intent(Intent.ACTION_VIEW);
    				intent.setData(Uri.parse("http://www.baidu.com"));
    				startActivity(intent);
    

    这里我们将一串网址字符串用uri.parse();解析成一个uri对象,然后通过intent.setData();传递出去.

    拨打电话?

    Intent intent=new Intent(Intent.ACTION_DIAL);
    				intent.setData(Uri.parse("tel:10010"));
    				startActivity(intent);
    
  • 相关阅读:
    【Vjudge】P1989Subpalindromes(线段树)
    【Luogu】P3358最长k可重区间集问题(费用流)
    【未有之有】洛森设定随笔
    14-Perl 引用
    13-Perl 子程序(函数)
    12-Perl 时间日期
    11-Perl 运算符
    10-Perl 循环
    9-Perl 条件语句
    8-Perl 哈希
  • 原文地址:https://www.cnblogs.com/stareblankly/p/5054047.html
Copyright © 2011-2022 走看看