接着上一篇RecentsActivity启动分析一继续分析RecentsActivity。先给大家看布局的结构图
简单的画了RecentsView部分,如下图所示
那接着就从RecentsActivity的构造方法开始分析
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//初始化RecentsTaskLoader
RecentsTaskLoader.initialize(this);
//获取SystemServicesProxy的对象
SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
mConfig = RecentsConfiguration.reinitialize(this, ssp);
// 初始化AppWidgetHost
mAppWidgetHost = new RecentsAppWidgetHost(this, Constants.Values.App.AppWidgetHostId);
//设置布局
setContentView(R.layout.recents);
//控件初始化
mRecentsView = (RecentsView) findViewById(R.id.recents_view);
mRecentsView.setCallbacks(this);
mRecentsView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
mEmptyViewStub = (ViewStub) findViewById(R.id.empty_view_stub);
mDebugOverlayStub = (ViewStub) findViewById(R.id.debug_overlay_stub);
mScrimViews = new SystemBarScrimViews(this, mConfig);
inflateDebugOverlay();
// Bind the search app widget when we first start up
//绑定搜索框
mSearchWidgetInfo = ssp.getOrBindSearchAppWidget(this, mAppWidgetHost);
// Register the broadcast receiver to handle messages when the screen is turned off
//注册广播接收器,接收来自系统的广播,处理系统消息
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
registerReceiver(mSystemBroadcastReceiver, filter);
//清除近期应用的按钮
ImageButton clearButton = (ImageButton) findViewById(R.id.clear_button);
clearButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
//清除所有任务
removeAllTasks();
}
}).start();
}
});
am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
pm = getPackageManager();
}
这个函数主要就是初始化控件,注册广播。
onStart()
@Override
protected void onStart() {
super.onStart();
MetricsLogger.visible(this, MetricsLogger.OVERVIEW_ACTIVITY);
//获取RecentsTaskLoader实例
RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
//获取SystemServiceProxy实例,这个类主要承接了RecentsActivity和系统服务的交互,包含获取最近任务列表,启动制定任务所在的应用等等。
SystemServicesProxy ssp = loader.getSystemServicesPro