https://blog.csdn.net/luzhenrong45/article/details/104799912
目录
一、设置应用的入口
Settings继承自SettingsActivity, 里面只是声明了一系列内部静态类,这些内部静态类对应着各个功能项的设置入口,除此之外Setting并没有做其他工作。因此,设置的启动加载实际是SettingsActivity里面实现的。
二、SettingsActivity
onCreate方法分析
主要是用来加载各个设置界面对应的Fragment
@Override
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
...
// Should happen before any call to getIntent()
getMetaData();
final Intent intent = getIntent();
// 获取要显示的Fragment的全类名
final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
final ComponentName cn = intent.getComponent();
final String className = cn.getClassName();
//判断当前activity是否是设置应用的activity
mIsShowingDashboard = className.equals(Settings.class.getName());
setContentView(mIsShowingDashboard ?
R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
if (!mIsShowingDashboard) {
//显示设置应用的非入口界面的Fragment
Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
switchToFragment(initialFragmentName, initialArguments, true, false,
mInitialTitleResId, mInitialTitle, false);
} else {
//显示设置应用的Fragment - DashboardSummary
switchToFragment(DashboardSummary.class.getName(), null, false, false,
mInitialTitleResId, mInitialTitle, false);
}
}
-->getMetaData()方法
通过获取当前activity的元数据,得到要加载的Fragment的全类名。
-->getIntent()方法
注意这个是复写了activity的getIntent方法,从Intent里获取要加载的Fragment全类名。
@Override
public Intent getIntent() {
Intent superIntent = super.getIntent();
String startingFragment = getStartingFragmentClass(superIntent);
// This is called from super.onCreate, isMultiPane() is not yet reliable
// Do not use onIsHidingHeaders either, which relies itself on this method
if (startingFragment != null) {
Intent modIntent = new Intent(superIntent);
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
Bundle args = superIntent.getExtras();
if (args != null) {
args = new Bundle(args);
} else {
args = new Bundle();
}
args.putParcelable("intent", superIntent);
modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
return modIntent;
}
return superIntent;
}
三、DashboardSummary
设置的入口界面Fragment
四、找设备应用中的各个模块的页面
上清单文件里找到Settings的内部类activity,然后找name为com.android.settings.FRAGMENT_CLASS
的meta-data
标签,它的value就是对应的界面的Fragment
0 条评论