1,AccountActivity的oncreate里先执行了方法jumpToMainTimeLineActivity()
private void jumpToMainTimeLineActivity() { String id = SettingUtility.getDefaultAccountId(); if (!TextUtils.isEmpty(id)) { AccountBean bean = AccountDBTask.getAccount(id); if (bean != null) { Intent start = MainTimeLineActivity.newIntent(bean); startActivity(start); finish(); } } }
SettingUtility.getDefaultAccountId()方法
support.settinghelper包下边有两个类SettingUtility和SettingHelper。前者是设置工具类,上层调用SettingUtility来设置和取出ID、字体、主题等具体的类型,SettingUtility调用底层的SettingHelper来操作SharedPreferences数据库。
如读取数据:
SettingUtility
public static String getDefaultAccountId() { return SettingHelper.getSharedPreferences(getContext(), "id", ""); }
private static SharedPreferences sharedPreferences = null; public static String getSharedPreferences(Context paramContext, String paramString1, String paramString2) { return getSharedPreferencesObject(paramContext).getString(paramString1, paramString2); } private static SharedPreferences getSharedPreferencesObject(Context paramContext) { if (sharedPreferences == null) sharedPreferences = PreferenceManager.getDefaultSharedPreferences(paramContext); return sharedPreferences; }
SettingUtility
public static void setDefaultAccountId(String id) { SettingHelper.setEditor(getContext(), "id", id); }SettingHelper
</pre><p><pre name="code" class="java"> public static void setEditor(Context paramContext, String paramString1, String paramString2) { getEditorObject(paramContext).putString(paramString1, paramString2).commit(); }//paramString1是键,paramString2是值。setEditor可根据不同的值类型(int,Boolean,String等)重载为不同方法 private static SharedPreferences.Editor getEditorObject(Context paramContext) { if (editor == null) editor = PreferenceManager.getDefaultSharedPreferences(paramContext).edit(); return editor; } private static SharedPreferences.Editor editor = null;
第一次运行程序时,SharedPreferences里一开始没有数据,因此id为“”。
如果以后注册了账号,id有值的话,就会进入
if (!TextUtils.isEmpty(id)) { AccountBean bean = AccountDBTask.getAccount(id); if (bean != null) { Intent start = MainTimeLineActivity.newIntent(bean); startActivity(start); finish(); } }
从数据库(SQLlite)里根据账号取出数据,如果有数据就进入MainTimeLineActivity
这里以后再研究。
目前id为“”,这里跳过,将执行super.onCreate,进入AbstractAppActivity