显示意图一般应用于同一个应用中 执行效率高
隐式意图用于不同的应用程序,要激活别的应用程序或者让自己的某一界面被别人激活
隐式意图执行过程:
1查询系统中所有Activity看有没有满足条件的Activity
2有-->有一个 直接打开。有多个 列表显示让用户选择
3没有-->程序异常终止 Activity not found exception
demo
1布局
<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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click"
android:text="向110发短信" />
</LinearLayout>
2MainActivity
package com.example.a69intentopensys;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click(View view) {
Intent intent = new Intent();
//如果一个应用有多个意图过滤器则 满足一个就可以打开该应用
//如果一个应用有多个action 满足一个即可
//如果一个应用有多个scheme 满足一个即可
intent.setAction("android.intent.action.SENDTO");
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("sms:110"));
startActivity(intent);
}
}