Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:55:49+00:00 2026-06-09T15:55:49+00:00

So, my question restated is when you go to Settings -> Accounts & Sync

  • 0

So, my question restated is when you go to Settings -> Accounts & Sync and select the an account that was created that your SyncAdapter is syncing with a cloud server, and select remove account, what happens as far as your SyncAdapter is concerned? There is a dialog that displays asking you to confirm and that the data on the phone associated with that account will be removed. I cannot easily believe that the framework can automatically remove the data my SyncAdapter has stored in the local database, but it seems to imply that removing the account will (and I would agree that is should) remove that data. Is there a addition to my SyncAdapter that will serve sort of as the callback for the account removal to handle deleting all the appropriate data from the local database? Maybe it has to be done through the AccountManager instead; my AccountManager gets notified when the account gets removed and from there I can trigger the data deletion without the SyncAdapter.

EDIT:
On a related note, is the sync manager calling my SyncAdapter for each account that it synchronizes when a new account is added? I see a onPerformSync(...) being executed for previously added accounts along with the just added account when I add an account, and would like to stop that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:55:50+00:00Added an answer on June 9, 2026 at 3:55 pm

    I discovered the solution is to make the app’s ContentProvider implement OnAccountsUpdateListener. Attach the ContentProvider as a listener in its onCreate method with account_manager.addOnAccountsUpdatedListener(this, null, false) and then implement the interface method like

    @Override
    public void onAccountsUpdated(final Account[] accounts) {
        Ln.i("Accounts updated.");
        final Iterable<String> account_list = new Iterable<String>() {
            @Override
            public Iterator<String> iterator() {
                return new Iterator<String>() {
                    private final Iterator<Account> account_list = Arrays.asList(accounts).iterator();
    
                    @Override
                    public boolean hasNext() {
                        return account_list.hasNext();
                    }
    
                    /** Extracts the next account name and wraps it in single quotes. */
                    @Override
                    public String next() {
                        return "'" + account_list.next().name + "'";
                    }
    
                    @Override
                    public void remove() { throw new UnsupportedOperationException("Not implemented"); }
                };
            }
        };
        final String account_set = TextUtils.join(", ", account_list);
        Ln.i("Current accounts: %s", account_set);
    
        // Removes content that is associated with accounts that are not currently connected
        final SelectionBuilder builder = new SelectionBuilder();
        builder.table(Tables.CALENDARS)
               .where(Calendars.CALENDAR_USER + " NOT IN (?)", account_set);
    
        new SafeAsyncTask() {
            @Override
            public Void call() throws Exception {
                _model.openWritableDatabase();
                _model.delete(builder);
                return null;
            }
        }.execute();
    
    
        getContext().getContentResolver().notifyChange(Calendars.NO_SYNC_URI, null, false);
    }
    

    I construct a String of the currently connected accounts, then build a SQL query with that String. I perform a delete on the database in a background thread on that query to remove the data associated with accounts not currently connected. And I notify that content changed, but does not need to synchronized with the server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question Is it possible to stop a Message Driven Bean (programmatically), so that it
Question context: let say that there is some really important row in config/locales/en.yml that
I know that this question have been asked several times. But I can't get
I created a C++ application that updates a SQLite database. The application reads a
Sorry if this question was supposed to be in Server Vault. I couldn't really
Okay, per suggestions on clarifying the intent I have restated the question. Hope this
I need to keep a table in sync with a recursive CTE query that
Completely restated my question: Problem: Losing reference to an iFrame with Mozilla firefox 3.6
UPDATE: QUESTION CLOSED: Fixed myself with a little backtracking. I'm using a framework that
Question from Object-Oriented JavaScript book: Imagine Array() doesn't exist and the array literal notation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.