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 7539109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:17:48+00:00 2026-05-30T07:17:48+00:00

I have had this issue for sometime on my app and it always bothered

  • 0

I have had this “issue” for sometime on my app and it always bothered me that I didn’t understand it’s behavior, but never cared about asking why, until now.

I have a ListView (implemented through a ListActivity) with a custom layout for each list item. With that I have a custom CursorAdapter to properly fill all the list item elements (overriding newView and bindView, the ViewHolder pattern is already guaranteed when doing it like this, refer to: https://codereview.stackexchange.com/q/1057 if needed).

This is the main Activity and there are 2 actions that can update the content of the ListView, create a new item or edit a current one. For both, the same activity is used (which adapts itself to the type of action), something like this:

startActivityForResult(intent, ACTIVITY_NOTE_EDITOR_CREATE);
startActivityForResult(intent, ACTIVITY_NOTE_EDITOR_EDIT);

What actually distinguishes the action type is the intent contents, the requestCode is ignored in the sub activity.

Now, the documentation has this to say about the method above:

When this activity exits, your onActivityResult() method will be
called with the given requestCode.

But I’m not using onActivityResult. Actually, I’m not doing anything when the sub activity exists (either in create or edit mode). And the behavior I’ve noticed so far is this:

  • Create: Almost all the time I return to the main activity, the ListView is automatically updated with the new item. However, sometimes, rarely though, the ListView is not populated with the new item. I need to destroy the main activity (exiting the app for instance) and recreate it and then the new item will be there.
  • Edit: I never noticed similar behavior as just described for the create action. So far, the ListView was always automatically updated with the new content changes.

My question is, what’s happening behind the scenes that makes my ListView to automatically update it’s contents when I never call cursor.requery() nor manually notify of any changes to the content? And why the hell doesn’t it work all the time?

Should I maybe force a cursor.requery() myself on onActivityResult?

public class MainActivity extends ListActivity {

    private static final int ACTIVITY_NOTE_EDITOR_CREATE = 0;

    private NotificationHelper mNotificationHelper;
    private AgendaNotesAdapter mAgendaAdapter;
    private Cursor mAllNotesCursor;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        mNotificationHelper = Program.getNotificationHelper();

        mAgendaAdapter = new AgendaNotesAdapter(this);
        mAgendaAdapter.open();

        initializeNotesListActivity();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent intent;

        switch(item.getItemId()) {
            case R.id.actionbar_item_new_note:
                intent = NoteEditorMainActivity.createIntent(this);
                startActivityForResult(intent, ACTIVITY_NOTE_EDITOR_CREATE);
                return true;
        }

        return false;
    }

    private void initializeNotesListActivity() {
        mAllNotesCursor = mAgendaAdapter.fetchAllNotes();
        startManagingCursor(mAllNotesCursor);

        NotesListAdapter notesAdapter = new NotesListAdapter(this, mAllNotesCursor,
                mNotificationHelper, mAgendaAdapter);

        setListAdapter(notesAdapter);
    }

}

P.S: I know about CursorLoader and it’s something in the roadmap, but I don’t have time to deal with such code rewrites for the time being. Just thought I’d let you know. For now, I just need to know what is happening with my current code.

  • 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-05-30T07:17:49+00:00Added an answer on May 30, 2026 at 7:17 am

    Your call to startManagingCursor() means that when the activity is stopped, the Cursor is deactivated, and when the activity is restarted, the Cursor is requeried.

    Should I maybe force a cursor.requery() myself on onActivityResult?

    This should automatically occur for your managed Cursor.

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

Sidebar

Related Questions

I am having trouble with the following SQL statement. I have had this issue
I would love to get some tips from other people that have had this
I'm very much a vb person, but have had to use this id number
We have/had a phantom delay in our app. This was traced to the initialisation
Apologies if this was already asked but, I have had a look and can't
I've done quite a bit of googling on this error but have had no
Sometimes I have come across this issue that whenever I change the order of
I know this isn't a unique issue but I've not had much luck finding
I have had this problem w/ two seperate WYSWYG editors in my rails application
I have had to do this several times, usually when trying to find in

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.