Resume Activity with back button

Posted by Hallik on Stack Overflow See other posts from Stack Overflow or by Hallik
Published on 2010-04-19T01:29:54Z Indexed on 2010/04/19 1:33 UTC
Read the original article Hit count: 318

Filed under:
|

I have an application I am creating with a DashboardActivity & a SettingsActivity. On the dashboard, I have one object displayed, but when I go into settings, I want to be able to select/deselect X options. Once the user clicks the back button, I save that data locally and to the server. Once the phone receives a success message from the server that it was stored properly, I want to reload the dashboard.

I thought I would do this with the onPause and onResume, but they are called when the DashboardActivity is first created. What would be the best way to reload the dashboard by calling my web service after the settings were saved to the server? Here is what I am doing when the back button is hit

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //Save data to the server once the user hits the back button
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        SchoolSearchActivity.this.divisionProxy = new DivisionProxy(SchoolSearchActivity.this.saveUserDivisionHandler);
        SchoolSearchActivity.this.divisionProxy.submitUserDivisions(SchoolSearchActivity.this.userDivisions, SchoolSearchActivity.this.user_id);
        //SchoolSearchActivity.this.finish();
        //Toast.makeText(SchoolSearchActivity.this, "Divisions Saved",Toast.LENGTH_LONG).show();
    }
    return true;
}

The above opens an HTTP connection, and when the response is received, the handler processes the response. I am going to: 1) throw up a progress dialog box letting the user know it's being submitted to the server, and once a response is received, 2) go back to the previous activity and call the "refresh" webservice again.

What's the best way to accomplish 1 & 2?

© Stack Overflow or respective owner

Related posts about android

Related posts about android-sdk