launchermodel.java_Android系统默认Home应用程序(Launcher)的启动过程源代码分析(4)...

Step 17. LoaderTask.loadAndBindAllApps

这个函数定义在packages/apps/Launcher2/src/com/android/launcher2/LauncherModel.java文件中:

publicclassLauncherModelextendsBroadcastReceiver {

......

privateclassLoaderTaskimplementsRunnable {

......

privatevoidloadAndBindAllApps() {

......

if(!mAllAppsLoaded) {

loadAllAppsByBatch();

if(mStopped) {

return;

}

mAllAppsLoaded = true;

} else{

onlyBindAllApps();

}

}

......

}

......

}

由于还没有加载过应用程序,这里的mAllAppsLoaded为false,于是就继续调用loadAllAppsByBatch函数来进一步操作了。

Step 18. LoaderTask.loadAllAppsByBatch

这个函数定义在packages/apps/Launcher2/src/com/android/launcher2/LauncherModel.java文件中:

publicclassLauncherModelextendsBroadcastReceiver {

......

privateclassLoaderTaskimplementsRunnable {

......

privatevoidloadAllAppsByBatch() {

......

finalIntent mainIntent =newIntent(Intent.ACTION_MAIN,null);

mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

finalPackageManager packageManager = mContext.getPackageManager();

List apps = null;

intN = Integer.MAX_VALUE;

intstartIndex;

inti=0;

intbatchSize = -1;

while(i 

if(i ==0) {

mAllAppsList.clear();

......

apps = packageManager.queryIntentActivities(mainIntent, 0);

......

N = apps.size();

......

if(mBatchSize ==0) {

batchSize = N;

} else{

batchSize = mBatchSize;

}

......

Collections.sort(apps,

newResolveInfo.DisplayNameComparator(packageManager));

}

startIndex = i;

for(intj=0; i

// This builds the icon bitmaps.

mAllAppsList.add(newApplicationInfo(apps.get(i), mIconCache));

i++;

}

finalbooleanfirst = i <= batchSize;

finalCallbacks callbacks = tryGetCallbacks(oldCallbacks);

finalArrayList added = mAllAppsList.added;

mAllAppsList.added = newArrayList();

mHandler.post(newRunnable() {

publicvoidrun() {

finallongt = SystemClock.uptimeMillis();

if(callbacks !=null) {

if(first) {

callbacks.bindAllApplications(added);

} else{

callbacks.bindAppsAdded(added);

}

......

} else{

......

}

}

});

......

}

......

}

......

}

......

}

函数首先构造一个CATEGORY_LAUNCHER类型的Intent:

finalIntent mainIntent =newIntent(Intent.ACTION_MAIN,null);

mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

接着从mContext变量中获得PackageManagerService的接口:

finalPackageManager packageManager = mContext.getPackageManager();

下一步就是通过这个PackageManagerService.queryIntentActivities接口来取回所有Action类型为Intent.ACTION_MAIN,并且Category类型为Intent.CATEGORY_LAUNCHER的Activity了。

我们先进入到PackageManagerService.queryIntentActivities函数中看看是如何获得这些Activity的,然后再回到这个函数中来看其余操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值