提示:在启动一个Activity前进行必要的存在检测很有必要,以免程序意外崩溃。

第一种:通过applicationId与package+activityPath

applicationId告诉系统活动在那个App内,进入App内就需要类路径找具体的Activity。

//applicationId:com.example.student0.caller CallerActivity.javaprivate final static int REQ_CODE = 0X2233;private final static String TARGET_APP_ID = "com.example.student0.recipient";private final static String TARGET_ACTIVITY_DIR = "com.student0.demo.RecipientActivity";ComponentName component = new ComponentName(TARGET_APP_ID, TARGET_ACTIVITY_DIR);Intent intent = new Intent();intent.setComponent(component);startActivityForResult(CallerActivity.this, intent);//applicationId:com.example.student0.recipient Manifest.xml......

第二种:通过自定义Action启动。

//applicationId:com.example.student0.recipient Manifest.xml        //applicationId:com.example.student0.caller CallerActivity.javaString targetActivityAction = "com.example.student0.helloWord";//与被调用的Activity的Action一致Intent intent = new Intent();intent.setAction(targetActivityAction);CallerActivity.this.startActivity(intent);

第三种:通过packageManager获取拥有对应软件包名(ApplicationId)的App的Launch活动。

//applicationId:com.example.student0.caller CallerActivity.javaIntent intent = getPackageManager().getLaunchIntentForPackage("com.example.student0.recipient");this.startActivity(intent);

第四种:通过设置可以响应的指定数据类型。

//applicationId:com.example.student0.recipient Mainfest.xml        //applicationId:com.example.student0.caller CallerActivity.javaUri uri = Uri.parse("gugu://...");Intent intent = new Intent();intent.setData(uri);

android:scheme。指定数据的协议部分。

android:host。指定数据的主机部分。

android:port。指定数据的端口部分。

android:path。指定主机名和端口后的部分,即相对路径。

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

一个activity可以响应多个android:scheme,当一条中同时存在host、port、path时,数据的格式需要满足该条中指定的所有协定。属性指定的响应数据类型,在网页中也能得到响应例如:

 

更多相关文章

  1. Android在ExpandableListView控制的基本使用
  2. Android(安卓)4.0 新增的显示数据集的桌面控件
  3. android之数据库和Content Provider(二)
  4. Android音频数据传输
  5. android在Fragment中使用ListView显示数据总结
  6. AsyncTask进度条加载网站数据到ListView
  7. Android应用程序访问远程数据库(mysql) is not allowed to conne
  8. Android(安卓)BLE蓝牙开发中读取数据时设置Notify的方法
  9. Android网络数据xml解析

随机推荐

  1. golang的zap怎么使用
  2. golang 如何模块化
  3. golang调试工具有哪些?
  4. golang的slice如何去重
  5. golang判断map中指定key是否存在
  6. golang指针传递和值传递的区别是什么?
  7. golang的hashmap怎么扩容
  8. golang 如何类型转换
  9. golang有类(class)吗?
  10. golang到底能做什么