List of usage examples for android.app LoaderManager restartLoader
public abstract <D> Loader<D> restartLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback);
From source file:com.tct.mail.ui.AbstractActivityController.java
/** * Sets the current folder if it is different from the object provided here. This method does * NOT notify the folder observers that a change has happened. Observers are notified when we * get an updated folder from the loaders, which will happen as a consequence of this method * (since this method starts/restarts the loaders). * @param folder The folder to assign//from ww w.j ava2s . c o m */ private void updateFolder(Folder folder) { if (folder == null || !folder.isInitialized()) { LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", folder); return; } if (folder.equals(mFolder)) { LogUtils.d(LOG_TAG, "AAC.setFolder(%s): Input matches mFolder", folder); return; } final boolean wasNull = mFolder == null; LogUtils.d(LOG_TAG, "AbstractActivityController.setFolder(%s)", folder.name); final LoaderManager lm = mActivity.getLoaderManager(); // updateFolder is called from AAC.onLoadFinished() on folder changes. We need to // ensure that the folder is different from the previous folder before marking the // folder changed. setHasFolderChanged(folder); mFolder = folder; // We do not need to notify folder observers yet. Instead we start the loaders and // when the load finishes, we will get an updated folder. Then, we notify the // folderObservers in onLoadFinished. mActionBarController.setFolder(mFolder); //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-S mActivity.invalidateOptionsMenu(); //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-E // Only when we switch from one folder to another do we want to restart the // folder and conversation list loaders (to trigger onCreateLoader). // The first time this runs when the activity is [re-]initialized, we want to re-use the // previous loader's instance and data upon configuration change (e.g. rotation). // If there was not already an instance of the loader, init it. if (lm.getLoader(LOADER_FOLDER_CURSOR) == null) { lm.initLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks); } else { lm.restartLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks); } if (!wasNull && lm.getLoader(LOADER_CONVERSATION_LIST) != null) { // If there was an existing folder AND we have changed // folders, we want to restart the loader to get the information // for the newly selected folder lm.destroyLoader(LOADER_CONVERSATION_LIST); } /// TCT: Fix the empty view will always flash out here. no need show empty view when folde changing, // folders, we want to restart the loader to get the information /// cause loadConversationListData would always destroy loader,and the cursor always be empty when do this. @{ // for the newly selected folder final ConversationListFragment conversationList = getConversationListFragment(); // TS: zheng.zou 2015-05-8 EMAIL BUGFIX-976970 DEL_S // lm.destroyLoader(LOADER_CONVERSATION_LIST); // TS: zheng.zou 2015-05-8 EMAIL BUGFIX-976970 DEL_E if (conversationList != null) { conversationList.getListView().setEmptyView(null); } loadConversationListData(true); }