当前位置: 首页 > news >正文

Launcher中Shortcut的创建流程简析

本文将以ContactsDirect dial为例,来解析在Launcher创建shortcut的流程

Direct dialAndroidManifest.xml(Contacts)中声明如下:

        <activity-alias android:name="alias.DialShortcut"
            android:targetActivity=".activities.ContactSelectionActivity"
            android:label="@string/shortcutDialContact"
            android:icon="@mipmap/ic_launcher_shortcut_directdial"
            android:enabled="@*android:bool/config_voice_capable">
            <intent-filter>
                <action android:name="android.intent.action.CREATE_SHORTCUT" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.CAR_MODE" />
            </intent-filter>
        </activity-alias>

这样,在LauncherWIDGETS页面便可找到Direct dial(android.intent.action.CREATE_SHORTCUT

我们将Direct dial拖拽到桌面后,会触发.activities.ContactSelectionActivity.选择一个联系人,就完成了Direct dial的创建。

点击该shortcut将跳转到给我们选择的联系人打电话界面。

下面是我打的Log,重要步骤都被标红了。

-----------launcher widget页面选择direct dialshortcut)并拖拽到launcher主界面-----------

DragController-->onTouchEvent()-->MotionEvent.ACTION_UP, try to do drop() 

DragController-->drop() 

Workspace-->onDrop() 

Workspace-->onDropExternal() 

Launcher-->processShortcutFromDrop()-->componentName: com.android.contacts/alias.DialShortcut

Launcher-->resetAddInfo() 

Launcher-->processShortcut() 

Launcher-->startActivityForResultSafely()-->requestCode : 1 

DragLayer-->clearAnimatedView() 

ContactSelectionActivity-->onCreate()--start 

ContactSelectionActivity-->onCreate()-->mActionCode : -1 

ContactSelectionActivity-->configureListFragment()-->mActionCOde : 120 

ContactSelectionActivity-->onCreate()--end 

Launcher-->updateRunning() 

--------------------------为新建的direct dial快捷方式选择一个联系人--------------------------

PhoneNumberPickerFragment-->onItemClick()-->position : 0, id : 1 

PhoneNumberPickerFragment-->pickPhoneNumber()-->uri : content://com.android.contacts/data/1 

ShortcutIntentBuilder-->createPhoneNumberShortcutIntent()-->uri : content://com.android.contacts/data/1, shortcutAction : android.intent.action.CALL 

ShortcutIntentBuilder-->PhoneNumberLoadingAsyncTask-->loadData()-->mDisplayName : gaojx, mPhotoId : 0, mPhoneNumber : 155 2487, mPhoneType : 2, mPhoneLabel : null 

ShortcutIntentBuilder-->PhoneNumberLoadingAsyncTask-->onPostExecute() 

ShortcutIntentBuilder-->createPhoneNumberShortcutIntent() 

PhoneNumberPickerFragment-->onShortcutIntentCreated() 

ContactSelectionActivity-->PhoneNumberPickerActionListener-->onShortcutIntentCreated() 

ContactSelectionActivity-->returnPickerResult()

Launcher-->onActivityResult()-->requestCode : 1, resultCode : -1

Launcher-->onActivityResult()-->resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID 

Launcher-->completeAdd()-->args.requestCode : 1

Launcher-->completeAddShortcut()-->container : -100, screen : 2, cellX : 1, cellY : 2 

Launcher-->createShortcut()-->start 

BubleTextView-->applyFromShortcutInfo()-->info.title : gaojx 

Launcher-->createShortcut()-->end 

Workspace-->createUserFolderIfNecessary() 

Workspace-->addToExistingFolderIfNecessary() 

LauncherModel-->addItemToDatabase() 

Workspace-->addInScreen() 

Launcher-->resetAddInfo() 

DragLayer-->clearAnimatedView() 

Launcher-->exitSpringLoadedDragModeDelayed()-->successfulDrop : true 

Launcher-->updateRunning() 

Launcher-->showWorkspace() 

Launcher-->showWorkspace()-->mState != State.WORKSPACE 

Launcher-->updateRunning() 

----------------------------点击launcher主界面上新建的direct dial-------------------------------- 

Launcher-->onClick() 

Launcher-->onClick()-->tag instanceof ShortcutInfo

Launcher-->startActivitySafely() 

Launcher-->startActivity()-->Action => android.intent.action.CALL, Data => tel:155%202487

OutgoingCallBroadcaster-->onCreate() 

OutgoingCallBroadcaster-->processIntent()-->intent=Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxxxxx flg=0x14800000 cmp=com.android.phone/.OutgoingCallBroadcaster bnds=[120,387][240,543] } 

Launcher-->updateRunning()

....................................................................................................

通过上面的Log我们可以看出shortcut的流程是:

一:声明时指定的targetActivity属性是Launcher创建shortcut时要使用的。即LauncherstartActivityForResultSafely将启动我们设定的targetActivity,让我们选择该shortcut对应的联系人。

二:选择完联系人后将调用LauncheronActivityResult()来真正完成shortcut的创建工作。

三:点击shortcut时将调用LauncheronClick函数处理点击事件,最终通过LauncherstartActivitySafely函数调用startActivity函数(参数intent是我们从onActivityResult()到的)完成该shortcut的使命。

转载于:https://www.cnblogs.com/Lefter/archive/2013/05/26/3100320.html

相关文章:

  • thymeltesys-基于Spring Boot Oauth2的扫码登录框架
  • windows下揪出java程序占用cpu很高的线程 并找到问题代码 死循环线程代码
  • 如何格式化日期和时间
  • [R] data.frame() creates list?
  • 任意选若干个不相邻的数得到的和最大【dp】
  • C++ sort使用两个参数来排序
  • SmallSlider 图片轮播插件
  • 旅游网站CheapAir.com以BCH作为比特币支付
  • 二叉排序树
  • 【spring cloud】spring cloud子module的pom文件添加依赖,出现unknown问题【maven】
  • docker安装启动停止
  • firefox 不支持innertext, 需要用innerhtml代替
  • CPU占用过高问题排查
  • 《Linux学习并不难》文件/目录管理(7):rmdir命令删除空目录
  • Eclipse 整后tomcat的webApps目录
  • -------------------- 第二讲-------- 第一节------在此给出链表的基本操作
  • 「前端早读君006」移动开发必备:那些玩转H5的小技巧
  • 【css3】浏览器内核及其兼容性
  • HomeBrew常规使用教程
  • JavaScript设计模式与开发实践系列之策略模式
  • Laravel Telescope:优雅的应用调试工具
  • MD5加密原理解析及OC版原理实现
  • Vue 重置组件到初始状态
  • VuePress 静态网站生成
  • 阿里研究院入选中国企业智库系统影响力榜
  • 阿里云购买磁盘后挂载
  • 前嗅ForeSpider中数据浏览界面介绍
  • 区块链分支循环
  • 让你的分享飞起来——极光推出社会化分享组件
  • 山寨一个 Promise
  • 设计模式 开闭原则
  • 双管齐下,VMware的容器新战略
  • 听说你叫Java(二)–Servlet请求
  • 应用生命周期终极 DevOps 工具包
  • 【云吞铺子】性能抖动剖析(二)
  • ​DB-Engines 11月数据库排名:PostgreSQL坐稳同期涨幅榜冠军宝座
  • ###STL(标准模板库)
  • #Linux(帮助手册)
  • #每日一题合集#牛客JZ23-JZ33
  • #中的引用型是什么意识_Java中四种引用有什么区别以及应用场景
  • (14)学习笔记:动手深度学习(Pytorch神经网络基础)
  • (iPhone/iPad开发)在UIWebView中自定义菜单栏
  • (动手学习深度学习)第13章 计算机视觉---微调
  • (附源码)spring boot基于Java的电影院售票与管理系统毕业设计 011449
  • (小白学Java)Java简介和基本配置
  • . ./ bash dash source 这五种执行shell脚本方式 区别
  • .htaccess配置重写url引擎
  • .Net 路由处理厉害了
  • .NET 中让 Task 支持带超时的异步等待
  • .NET 中使用 Mutex 进行跨越进程边界的同步
  • .NET开发不可不知、不可不用的辅助类(三)(报表导出---终结版)
  • .NET运行机制
  • .net知识和学习方法系列(二十一)CLR-枚举
  • @RequestBody与@ResponseBody的使用
  • [Android]Tool-Systrace