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

  • Home
  • SEARCH
  • 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 8913261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:24:55+00:00 2026-06-15T04:24:55+00:00

I have a synchronicity problem. I have searched and cannot find a question with

  • 0

I have a synchronicity problem. I have searched and cannot find a question with the same conditions as mine. Pointers are welcome.

Android 4.1.2 on Eclipse 4.2.1

I have two activities; let’s call them ListActivity and DetailActivity. On a button press on ListActivity, I start DetailActivity. When the user makes changes to data in the DetailActivity and then clicks the back button, I want to do two things. First, I want to save changes to the database if a dirty flag is true. Second, I want to return an Intent to the onActivityResult() method of the ListActivity.

The problem is one of timing. Since I want to do database updating, I read that it is best practices to do this in the onStop() method of the DetailActivity. Right after I update the database I set up the Intent and call the setReult() method in the DetailActivity.

_resultIntent = new Intent();  
_resultIntent.putExtra(ListActivity .DETAIL_RESULT, _currentData);  
Log.d("ListActivity.setUpReturn()", "checkpoint");  
setResult(Activity.RESULT_OK, _resultIntent);  

The onActivityResult() method of the ListActivity is called before I have a chance to set the result. I placed Log calls throughout and what appears to happen is the following:

1) The user is in the DetailActivity and changes some data setting the dirty flag to true.
2) The user clicks the system back button.
3) The DetailActivity disappears from the screen.
4) The ListActivity re-appears.
5) The Log notes the onActivityResult(), onRestart(), onStart(), and onResume() methods of ListActivity execute in that order
6) Some other stuff is logged.
7) The Log FINALLY notes that the onStop() method of the DetailActiviy executes.

This means that by the time I am updating the database and setting up the result Intent, the calling activity has already gone past the point of using it.

I’d rather not constantly update the database. I’d rather put this into the onStop() method like the best practices says, but I don’t know how to get around the issue of timing. Any suggestions? Am I doing something obviously wrong?

  • 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-15T04:24:57+00:00Added an answer on June 15, 2026 at 4:24 am

    I would rather rely on event based code logic rather than on probability. You could try the following.

    *1) The user is in the DetailActivity and changes some data setting the dirty flag to true.
    2) The user clicks the system back button.
    *

    Override the onBackPressed method and perform your database operation right there and once the DB operation is performed you can call the super.onBackPressed() method and let the Android Activity stack take over.
    Mind you DB operation could be time consuming and hence it is also recommended to use AsyncTask with callback and only then call finish().

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

Sidebar

Related Questions

Have such a problem, hope you'll help me.. Can't find anywhere. Here is the
Well, this is the exact opposite problem that I normally have with Javascript synchronicity
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
have a nice day. I got problem when trying to create an image from
Have a problem, I'm about to rebuild the search feature on my site, but
Have a look on following application http://itunes.apple.com/us/app/fatbooth/id372268904?mt=8 i think they are using the same
Have a problem that seems easy on paper but i'm having a big problem
Have a simple iPhone app with a single UIViewController and two Views in one
have two line segment in the space, how to construct a surface with two

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.