启动一个Activity,可以直接使用Intent,例如:

 Intent intent = new Intent(Intent.ACTION_SEND);
...
startActivity(intent );

Start an Activity with the Intent

(图1)

如果该Intent对应了多个应用可以处理,会出现一个对话框让用户来确定使用哪一个应用来响应。如果每次执行这样的Action,用户都希望用同样的应用来处理,可以选中对话框底部的复选框“Use as default for this action”,避免每次都选择的麻烦。


但是,如果一个ACTION可以被多个应用处理,但用户希望每次使用时使用不同的应用来响应。比如“分享”功能,这次的分享可能是想通过“新浪微博”,下一个的分享就可能是“微信”。遇到这种情况,我们就需要显示的使用一个App Chooser来处理。

 Intent intent = new Intent(Intent.ACTION_SEND);
... // Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show chooser
Intent chooser = Intent.createChooser(intent, title); // Verify the intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}

Start activity with App Chooser

(图2)

使用App Chooser,用户就不能指定默认的处理应用。


之前一直没有搞清楚为什么使用App Chooser来启动一个Activity,还傻傻的认为跟直接使用Intent来startActivity相比只是多了一个可以定制title显示。通过上面的比较,相信你已经了解了为什么要使用App Chooser,以及什么情况下来使用App Chooser。

PS:有事没事去Android的官方网站溜达溜达,总会有些或多或少的收获。百度快餐,少用为好。

Start activity with App Chooser or not ?的更多相关文章

  1. AppManager类,管理Activity和App

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); / ...

  2. Android移动APP开发笔记——Cordova(PhoneGap)通过CordovaPlugin插件调用 Activity 实例

    引言 Cordova(PhoneGap)采用的是HTML5+JavaScript混合模式来开发移动手机APP,因此当页面需要获取手机内部某些信息时(例如:联系人信息,坐标定位,短信等),程序就需要调用 ...

  3. Android Activity启动流程, app启动流程,APK打包流程, APK安装过程

    1.Activity启动流程 (7.0版本之前) 从startActivity()开始,最终都会调用startActivityForResult() 在该方法里面会调用Instrumentation. ...

  4. Android四大组件之Activity详解——创建和启动Activity

    前面我们已经对Activity有过简单的介绍: Android开发——初始Activity Android开发——响应用户事件 Android开发——Activity生命周期 先来看一下最终结果 项目 ...

  5. 6、二、App Components(应用程序组件):1、Intents and Intent Filters(意图和意图过滤器)

    1.Intents and Intent Filters(意图和意图过滤器) 1.0.Intents and Intent Filters(意图和意图过滤器) An Intent is a messa ...

  6. 【android官方文档】与其他App交互

    发送用户到另外一个App YOU SHOULD ALSO READ 内容分享 One of Android's most important features is an app's ability ...

  7. Xamarin Android Activity全屏的两种方式

    方式一 直接在Activity的Attribute中定义 如下 在 MainActivity 中 [Activity(Label = "app", MainLauncher = t ...

  8. [Android]从Launcher开始启动App流程源码分析

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5017056.html 从Launcher开始启动App流程源码 ...

  9. app启动时间命令

    app启动: 冷启动和热启动 冷启动方式: adb shell am start -W -n package/activity 停止app命令: adb shell am force-stop pac ...

随机推荐

  1. asp遍历前端的所有控件

    //遍历ID为Panel1的panel里的所有label控件 foreach (Control ctl in this.Panel1.Controls) { //判断类型为Label的 if (ctl ...

  2. C语言数据结构-栈的实现-初始化、销毁、长度、取栈顶元素、查找、入栈、出栈、显示操作

    1.数据结构-栈的实现-C语言 #define MAXSIZE 100 //栈的存储结构 typedef struct { int* base; //栈底指针 int* top; //栈顶指针 int ...

  3. jupyter notebook 设置默认目录

    1.打开 cmd 输入命令 jupyter notebook --generate-config 可以看到生成文件的路径,这个就是生成的配置文件jupyter_notebook_config.py, ...

  4. Canvas 与 Image 相互转换

    转换 Image为 Canvas 要把图片转换为Canvas(画板,画布),可以使用canvas元素 context 的drawImage方法: 代码如下: // 把image 转换为 canvas对 ...

  5. mpvue 小程序应用拖动排序

    <template> <div> <div style="width:90%;height:40px;line-height:40px;margin:auto; ...

  6. Spring----. ref的用法

      ref元素是用在property中,来设置需要引用的容器管理的其它Bean.     它的用法:<ref bean|local|parent="someBean"> ...

  7. spring 配置properties 编码

    <!-- properties 配置文件 --> <bean id="propertyConfigurer" class="org.springfram ...

  8. Canvas 动态小球重叠效果

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. Java RESTful框架的性能比较

    https://colobu.com/2015/11/17/Jax-RS-Performance-Comparison/

  10. NET Core 不错教程***************

    Twinhead 当前标签: .Net Core   RabbitMQ教程 Twinhead 2019-01-26 20:02 阅读:5 评论:0     缓存击穿.缓存穿透和缓存雪崩 Twinhea ...