博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Launcher中Shortcut的创建流程简析
阅读量:4560 次
发布时间:2019-06-08

本文共 3949 字,大约阅读时间需要 13 分钟。

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

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

这样,在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

你可能感兴趣的文章
Bzoj2673 3961: [WF2011]Chips Challenge 费用流
查看>>
dwz tree组件 取得所选择的值
查看>>
sql like模糊查询的条件拼接
查看>>
python 3 廖雪峰博客笔记(一) python特性
查看>>
JAVA学习心得
查看>>
[转]推荐highcharts学习网址
查看>>
centos7下自定义服务启动和自动执行脚本
查看>>
docker上部署nginx容器80端口自动转443端口
查看>>
ps命令查看子进程
查看>>
2019春第七周编程总结
查看>>
angularjs1-7,http,location
查看>>
sass01
查看>>
Java 8 Lambda 表达式
查看>>
codeblocks 教程
查看>>
微信小微商户申请入驻
查看>>
Java的并发和多处理器的并行的理解
查看>>
1178.复数集合
查看>>
1174.查找第k小数
查看>>
优先队列(堆)
查看>>
C语言中函数参数传递的本质是值传递
查看>>