Example usage for android.app LoaderManager destroyLoader

List of usage examples for android.app LoaderManager destroyLoader

Introduction

In this page you can find the example usage for android.app LoaderManager destroyLoader.

Prototype

public abstract void destroyLoader(int id);

Source Link

Document

Stops and removes the loader with the given ID.

Usage

From source file:com.android.browser.BookmarksPageCallbacks.java

@Override
public void onDestroyView() {
    super.onDestroyView();
    mGrid.setBreadcrumbController(null);
    mGrid.clearAccounts();/* w w  w.ja  va  2  s .  co  m*/
    LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ACCOUNTS);
    for (int id : mBookmarkAdapters.keySet()) {
        lm.destroyLoader(id);
    }
    mBookmarkAdapters.clear();
}

From source file:com.borqs.browser.BookmarksPageCallbacks.java

@Override
public void onDestroyView() {
    super.onDestroyView();
    mGrid.setBreadcrumbController(null);
    mGrid.clearAccounts();/*from   w  ww. jav a 2 s  .  co m*/
    LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ACCOUNTS);
    for (int id : mBookmarkAdapters.keySet()) {
        lm.destroyLoader(id);
        BrowserBookmarksAdapter adapter = mBookmarkAdapters.get(id);
        if (adapter != null)
            adapter.quit();
    }
    mBookmarkAdapters.clear();
}

From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java

public void onDestroyView() {
    // super.onDestroyView();
    mGrid.setBreadcrumbController(null);
    mGrid.clearAccounts();//from  ww  w.  j  a v  a  2 s.c o m
    LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ACCOUNTS);
    for (int id : mBookmarkAdapters.keySet()) {
        lm.destroyLoader(id);
        BrowserBookmarksAdapter adapter = mBookmarkAdapters.get(id);
        if (adapter != null)
            adapter.quit();
    }
    mBookmarkAdapters.clear();
}

From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java

@Override
public void onDestroy() {
    super.onDestroy();

    mGrid.setBreadcrumbController(null);
    mGrid.clearAccounts();/*from  w w  w  .ja  v a 2s.  co m*/
    LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ACCOUNTS);
    for (int id : mBookmarkAdapters.keySet()) {
        lm.destroyLoader(id);
        BrowserBookmarksAdapter adapter = mBookmarkAdapters.get(id);
        if (adapter != null)
            adapter.quit();
    }
    mBookmarkAdapters.clear();
}

From source file:com.frostwire.android.gui.fragments.MyFilesFragment.java

private void reloadFiles(byte fileType) {
    try {/* www  . ja  v  a 2  s. co m*/
        if (isAdded()) {
            LoaderManager loaderManager = getLoaderManager();
            loaderManager.destroyLoader(LOADER_FILES_ID);
            Bundle bundle = new Bundle();
            bundle.putByte("fileType", fileType);
            loaderManager.restartLoader(LOADER_FILES_ID, bundle, this);
        }
    } catch (Throwable t) {
        LOG.error(t.getMessage(), t);
    }
}

From source file:com.chen.mail.ui.FolderListFragment.java

/**
 * Sets the current account to the one provided here.
 * @param account the current account to set to.
 *///  w ww.  j a v a  2  s .  c  o  m
private void setSelectedAccount(Account account) {
    final boolean changed = (account != null)
            && (mCurrentAccount == null || !mCurrentAccount.uri.equals(account.uri));
    mCurrentAccount = account;
    if (changed) {
        // We no longer have proper folder objects. Let the new ones come in
        mCursorAdapter.setCursor(null);
        // If currentAccount is different from the one we set, restart the loader. Look at the
        // comment on {@link AbstractActivityController#restartOptionalLoader} to see why we
        // don't just do restartLoader.
        final LoaderManager manager = getLoaderManager();
        manager.destroyLoader(FOLDER_LIST_LOADER_ID);
        manager.restartLoader(FOLDER_LIST_LOADER_ID, Bundle.EMPTY, this);
        manager.destroyLoader(ALL_FOLDER_LIST_LOADER_ID);
        manager.restartLoader(ALL_FOLDER_LIST_LOADER_ID, Bundle.EMPTY, this);
        // An updated cursor causes the entire list to refresh. No need to refresh the list.
        // But we do need to blank out the current folder, since the account might not be
        // synced.
        mSelectedFolderUri = FolderUri.EMPTY;
        mCurrentFolderForUnreadCheck = null;
    } else if (account == null) {
        // This should never happen currently, but is a safeguard against a very incorrect
        // non-null account -> null account transition.
        LogUtils.e(LOG_TAG, "FLF.setSelectedAccount(null) called! Destroying existing loader.");
        final LoaderManager manager = getLoaderManager();
        manager.destroyLoader(FOLDER_LIST_LOADER_ID);
        manager.destroyLoader(ALL_FOLDER_LIST_LOADER_ID);
    }
}

From source file:com.tct.mail.ui.FolderListFragment.java

/**
 * Sets the current account to the one provided here.
 * @param account the current account to set to.
 *//*from ww w.  j  av  a  2 s  . c o  m*/
private void setSelectedAccount(Account account) {
    final boolean changed = (account != null)
            && (mCurrentAccount == null || !mCurrentAccount.uri.equals(account.uri));
    mCurrentAccount = account;
    if (changed) {
        // Verify that the new account supports sending application feedback
        updateFooterItems();
        // We no longer have proper folder objects. Let the new ones come in
        mFolderAdapter.setCursor(null);
        // If currentAccount is different from the one we set, restart the loader. Look at the
        // comment on {@link AbstractActivityController#restartOptionalLoader} to see why we
        // don't just do restartLoader.
        final LoaderManager manager = getLoaderManager();
        manager.destroyLoader(FOLDER_LIST_LOADER_ID);
        manager.restartLoader(FOLDER_LIST_LOADER_ID, Bundle.EMPTY, this);
        manager.destroyLoader(ALL_FOLDER_LIST_LOADER_ID);
        manager.restartLoader(ALL_FOLDER_LIST_LOADER_ID, Bundle.EMPTY, this);
        // An updated cursor causes the entire list to refresh. No need to refresh the list.
        // But we do need to blank out the current folder, since the account might not be
        // synced.
        mSelectedFolderUri = FolderUri.EMPTY;
        mCurrentFolderForUnreadCheck = null;

        // also set/update the mini-drawer
        if (mMiniDrawerEnabled) {
            //foobar
            mMiniDrawerView.refresh();
        }

    } else if (account == null) {
        // This should never happen currently, but is a safeguard against a very incorrect
        // non-null account -> null account transition.
        LogUtils.e(LOG_TAG, "FLF.setSelectedAccount(null) called! Destroying existing loader.");
        final LoaderManager manager = getLoaderManager();
        manager.destroyLoader(FOLDER_LIST_LOADER_ID);
        manager.destroyLoader(ALL_FOLDER_LIST_LOADER_ID);
    }
}

From source file:com.android.mail.ui.FolderListFragment.java

/**
 * Sets the current account to the one provided here.
 * @param account the current account to set to.
 *///  w  w  w .j  a  v  a 2s .c om
private void setSelectedAccount(Account account) {
    final boolean changed = (account != null)
            && (mCurrentAccount == null || !mCurrentAccount.uri.equals(account.uri));
    mCurrentAccount = account;
    if (changed) {
        // Verify that the new account supports sending application feedback
        updateFooterItems();
        // We no longer have proper folder objects. Let the new ones come in
        mFolderAdapter.setCursor(null);
        // If currentAccount is different from the one we set, restart the loader. Look at the
        // comment on {@link AbstractActivityController#restartOptionalLoader} to see why we
        // don't just do restartLoader.
        final LoaderManager manager = getLoaderManager();
        manager.destroyLoader(FOLDER_LIST_LOADER_ID);
        manager.restartLoader(FOLDER_LIST_LOADER_ID, Bundle.EMPTY, this);
        manager.destroyLoader(ALL_FOLDER_LIST_LOADER_ID);
        manager.restartLoader(ALL_FOLDER_LIST_LOADER_ID, Bundle.EMPTY, this);
        // An updated cursor causes the entire list to refresh. No need to refresh the list.
        // But we do need to blank out the current folder, since the account might not be
        // synced.
        mSelectedFolderUri = FolderUri.EMPTY;
        mCurrentFolderForUnreadCheck = null;

        // also set/update the mini-drawer
        if (mMiniDrawerAccountsAdapter != null) {
            mMiniDrawerAccountsAdapter.setAccounts(getAllAccounts(), mCurrentAccount);
        }

    } else if (account == null) {
        // This should never happen currently, but is a safeguard against a very incorrect
        // non-null account -> null account transition.
        LogUtils.e(LOG_TAG, "FLF.setSelectedAccount(null) called! Destroying existing loader.");
        final LoaderManager manager = getLoaderManager();
        manager.destroyLoader(FOLDER_LIST_LOADER_ID);
        manager.destroyLoader(ALL_FOLDER_LIST_LOADER_ID);
    }
}

From source file:com.android.mail.ui.AbstractActivityController.java

/**
 * {@link LoaderManager} currently has a bug in
 * {@link LoaderManager#restartLoader(int, Bundle, android.app.LoaderManager.LoaderCallbacks)}
 * where, if a previous onCreateLoader returned a null loader, this method will NPE. Work around
 * this bug by destroying any loaders that may have been created as null (essentially because
 * they are optional loads, and may not apply to a particular account).
 * <p>/* www  .ja v  a 2s .c o m*/
 * A simple null check before restarting a loader will not work, because that would not
 * give the controller a chance to invalidate UI corresponding the prior loader result.
 *
 * @param id loader ID to safely restart
 * @param handler the LoaderCallback which will handle this loader ID.
 * @param args arguments, if any, to be passed to the loader. Use {@link Bundle#EMPTY} if no
 *             arguments need to be specified.
 */
private void restartOptionalLoader(int id, LoaderManager.LoaderCallbacks handler, Bundle args) {
    final LoaderManager lm = mActivity.getLoaderManager();
    lm.destroyLoader(id);
    lm.restartLoader(id, args, handler);
}

From source file:com.android.mail.ui.AbstractActivityController.java

/**
 * Load the conversation list early for the given folder. This happens when some UI element
 * (usually the drawer) instructs the controller that an account change or folder change is
 * imminent. While the UI element is animating, the controller can preload the conversation
 * list for the default inbox of the account provided here or to the folder provided here.
 *
 * @param nextAccount The account which the app will switch to shortly, possibly null.
 * @param nextFolder The folder which the app will switch to shortly, possibly null.
 *///from ww w.j  a va 2 s .c o  m
protected void preloadConvList(Account nextAccount, Folder nextFolder) {
    // Fire off the conversation list loader for this account already with a fake
    // listener.
    final Bundle args = new Bundle(2);
    if (nextAccount != null) {
        args.putParcelable(BUNDLE_ACCOUNT_KEY, nextAccount);
    } else {
        args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount);
    }
    if (nextFolder != null) {
        args.putParcelable(BUNDLE_FOLDER_KEY, nextFolder);
    } else {
        LogUtils.e(LOG_TAG, new Error(), "AAC.preloadConvList(): Got an empty folder");
    }
    mFolder = null;
    final LoaderManager lm = mActivity.getLoaderManager();
    lm.destroyLoader(LOADER_CONVERSATION_LIST);
    lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks);
}