Android学习篇章26-Intent显示与隐式启动
来源:互联网 发布:tower软件下载 编辑:程序博客网 时间:2024/05/16 05:40
MainActivity:
public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}public void clickBtn(View view){int id=view.getId();if(id==R.id.btn1){//显式打开//Intent intent=new Intent(this,SecondActivity.class);// startActivity(intent);Intent intent=new Intent();//设定intent要启动的组件名称 这是典型的显式启动ComponentName cn=new ComponentName(this, SecondActivity.class);intent.setComponent(cn);}else if(id==R.id.btn2){//隐式启动Intent 不会直接指明要启动的组件名称//而是通过给Intent设定的操作(Action)和要传送的数据(Data)来间接指明组件 Intent intent =new Intent(); //使用action指明Intent要执行的操作 这里操作的名称是ACTION_VIEW //具体的值android.intent.action.VIEW 代表了一个查看的操作 intent.setAction(Intent.ACTION_VIEW); //这里指明要查看的数据 这个数据的书写格式必须是URI格式 intent.setData(Uri.parse("http://www.sina.com")); //那么复合这个设定条件的Activity将会被Android启动 //这种启动方式被称之为隐式启动 这种启动方式是最常用的Intent的使用形式 //也是Android推荐的 startActivity(intent); }else if(id==R.id.btn3){Intent intent=new Intent();intent.setAction(Intent.ACTION_VIEW);//设定复合Uri规范的电话号码//Android会根据你所设定的Action以及data 和category 综合筛选出复合条件的Activity(组件)//intent.setData(Uri.parse("email:13830515@qq.com"));intent.setData(Uri.parse("tel:13874938836"));startActivity(intent);}else if(id==R.id.btn4){Intent intent=new Intent();Log.i("test", "aaaaa");//同一个Activity可以支持不同的Action//筛选条件的匹配是依赖于各个组件在manifest.xml中配置时所设定的intent-filterintent.setAction(Intent.ACTION_EDIT);intent.setData(Uri.parse("tel:13874938836"));startActivity(intent);}else if(id==R.id.btn5){Intent intent=new Intent();intent.setAction(Intent.ACTION_VIEW);intent.setData(Uri.parse("http://localhost:8081/aaaa/a.jpg"));startActivity(intent);}else if(id==R.id.btn6){Intent intent=new Intent();intent.setAction("android.intent.action.My_Test");//intent.setData(Uri.parse("http://www.sina.com")); //设置Catagory分类//intent.setType(type)startActivity(intent);}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.intent2" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.CALL_PHONE"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=com.intent2.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.intent2.SecondActivity" android:label="@string/title_activity_second" > </activity> <activity android:name="com.intent2.ThirdActivity" android:label="@string/title_activity_third" > <intent-filter> <action android:name="android.intent.action.VIEW"/> <action android:name="android.intent.action.My_Test"/> <data android:scheme="tel"/> <!-- 如果这个Activity想要被隐式打开 那么必须设定category为default --> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> </application></manifest>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <Button android:id="@+id/btn1" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="clickBtn" android:text="显式打开Activity" /> <Button android:id="@+id/btn2" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="clickBtn" android:text="隐式打开浏览器" /> <Button android:id="@+id/btn3" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="clickBtn" android:text="隐式打开拨号界面" /> <Button android:id="@+id/btn4" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="clickBtn" android:text="隐式打开通话界面" /> <Button android:id="@+id/btn5" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="clickBtn" android:text="隐式打开第3个窗口" /> <Button android:id="@+id/btn6" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="clickBtn" android:text="隐式打开第3个窗口_自定义Action" /></LinearLayout>
- Android学习篇章26-Intent显示与隐式启动
- Android学习篇章50-MediaStore-Intent启动照相
- Intent显示启动与隐式启动
- Android -- 显示Intent与隐式Intent的应用
- Android:Intent 显示和隐式 学习
- Android中 intent 显式启动与隐式启动
- 显示Intent与隐式Intent
- Intent 显示与隐式
- Android学习篇章35-Service基础-广播开机启动服务
- Android入门学习篇章
- Android开发学习笔记(4):浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android Intent学习之 隐式意图& 显示意图& intent 跳转问题
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- java错误:使用了未经检查或不安全的操作
- wpf 获得combobox中当前选中值的方法
- LINUX进程管理-2
- 图解Hadoop分布式文件系统HDFS
- python安装httplib2的一些注意点
- Android学习篇章26-Intent显示与隐式启动
- 01-HTML-介绍-超链接-表格
- LINUX块I/O层
- Android Smart Image View
- LINUX进程地址空间
- Android之使用Android-query框架进行开发(一)
- Android之使用Android-query框架进行开发(二)
- Oracle中rowid与rownum的区别
- 中断和中断处理程序