/** There's no guarantee that this function is ever called. */
  @Override
  public void onTerminate() {
    super.onTerminate();

    unregisterReceiver(mModel);
    // (BugID:134985 by wenliang.dwl) for desktop continuous feature
    unregisterReceiver(mContinuousHomeShellReceiver);

    ContentResolver resolver = getContentResolver();
    resolver.unregisterContentObserver(mFavoritesObserver);

    /* YUNOS BEGIN */
    // ##date:2013/11/20 ##author:zhangqiang.zq
    // add theme icon
    ThemeChangedListener.getInstance(getApplicationContext()).unregister(getApplicationContext());
    /* YUNOS END */

    FontChangedListener.getInstance(getApplicationContext()).unregister(getApplicationContext());

    // edit by dongjun for traffic panel begin
    this.mModel.destroy();
    mContext = null;
    // edit by dongjun for traffic panel end
  }
  /* YUNOS END */
  @Override
  public void onCreate() {
    super.onCreate();
    // edit by dongjun for traffic panel begin
    mContext = getApplicationContext();
    // edit by dongjun for traffic panel end

    /* YUNOS BEGIN */
    // ##date:2013/11/28 ##author:hongxing.whx
    // backup restore functionality support
    handleRestore();
    /* YUNOS END */

    /* YUNOS BEGIN */
    // ##date:2014/04/15 ##author:nater.wg ##BugID:110407
    // Enhance ConfigManager.
    ConfigManager.init();
    /* YUNOS END */

    // set sIsScreenXLarge and sScreenDensity *before* creating icon cache
    try {
      sIsScreenLarge = getResources().getBoolean(R.bool.is_large_screen);
      sIsMainmenuMode = getResources().getBoolean(R.bool.is_mainmenu_mode);
    } catch (Exception e) {
      sIsScreenLarge = false;
    }
    Log.d(TAG, "sIsScreenLarge=" + sIsScreenLarge);
    sScreenDensity = getResources().getDisplayMetrics().density;
    sScreenWidth = getResources().getDisplayMetrics().widthPixels;
    sScreenHeight = getResources().getDisplayMetrics().heightPixels;

    mWidgetPreviewCacheDb = new WidgetPreviewLoader.CacheDb(this);
    mIconManager = new IconManager(this);
    mModel = new LauncherModel(this);
    mContinuousHomeShellReceiver = new ContinuousHomeShellReceiver(this);

    // Register intent receivers
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
    filter.addDataScheme("package");
    registerReceiver(mModel, filter);
    filter = new IntentFilter();
    filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
    filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    filter.addAction(Intent.ACTION_LOCALE_CHANGED);
    filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    registerReceiver(mModel, filter);
    filter = new IntentFilter();
    filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
    registerReceiver(mModel, filter);
    filter = new IntentFilter();
    filter.addAction(SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED);
    registerReceiver(mModel, filter);

    // add by dongjun for appstore begin
    filter = new IntentFilter();
    filter.addAction(AppDownloadManager.ACTION_APP_DWONLOAD_TASK);
    registerReceiver(mModel, filter);
    // add by dongjun for appstore end

    // added by wenliang.dwl for broadcast send from homeshell
    filter = new IntentFilter();
    filter.addAction(AppDownloadManager.ACTION_HS_DOWNLOAD_TASK);
    registerReceiver(mModel, filter);

    // for layout change
    filter = new IntentFilter();
    filter.addAction(LauncherModel.ACTION_HOMESHELL_LAYOUT_CHANGE);
    /* YUNOS BEGIN */
    // ##date:2014/06/05 ##author:hongchao.ghc ##BugID:126343
    // for settings show icon mark
    filter.addAction(LauncherModel.ACTION_UPDATE_LAYOUT);
    /* YUNOS END */
    registerReceiver(mModel, filter);

    // (BugID:134985 by wenliang.dwl) for desktop continuous feature
    filter = new IntentFilter();
    filter.addAction(ContinuousHomeShellReceiver.CONTINUOUS_HOMESHELL_SHOW_ACTION);
    registerReceiver(mContinuousHomeShellReceiver, filter);

    // bugid: 5232096: register ACTION_APPLICATION_NOTIFICATION intent
    filter = new IntentFilter();
    filter.addAction(IconDigitalMarkHandler.ACTION_APPLICATION_NOTIFICATION);
    registerReceiver(mModel, filter);

    IconDigitalMarkHandler.getInstance();
    // end of 5232096

    // Register for changes to the favorites
    ContentResolver resolver = getContentResolver();
    resolver.registerContentObserver(
        LauncherSettings.Favorites.CONTENT_URI, true, mFavoritesObserver);

    /* YUNOS BEGIN */
    // ##date:2013/11/20 ##author:zhangqiang.zq
    // add theme icon
    ThemeChangedListener.getInstance(getApplicationContext()).register(getApplicationContext());
    ThemeChangedListener.getInstance(getApplicationContext()).addListener(this);
    /* YUNOS END */

    FontChangedListener.getInstance(getApplicationContext()).register(getApplicationContext());
    FontChangedListener.getInstance(getApplicationContext()).addListener(this);

    /*YUNOS BEGIN added by xiaodong.lxd for push to talk*/
    if (CheckVoiceCommandPressHelper.PUSH_TO_TALK_SUPPORT) {
      mVuiHelper = CheckVoiceCommandPressHelper.getInstance();
      filter = new IntentFilter();
      filter.addAction(CheckVoiceCommandPressHelper.BROADCAST_PUSHTALK_SWITCH_CHANGED);
      registerReceiver(mVuiHelper.mSwitchReceiver, filter);
      if (mVuiHelper.isVoiceSwitchOn()) {
        mVuiHelper.initVoiceService();
      }
    }
    /*YUNOS END*/

    /*YUNOS BEGIN*/
    // ##date:2014/1/9 ##author:zhangqiang.zq
    // smart search
    HanziToPinyin.getInstance().initHanziPinyinForAllChars(getContext());
    /*YUNOS END*/

    /*YUNOS BEGIN*/
    // ##date:2014/8/1 ##author:zhangqiang.zq
    // favorite app
    mRecommendTask = new RecommendTask(getApplicationContext());
    /*YUNOS END*/
  }