0

I'm able to edit & save data from one Activity(EditActivity.java), but the updated data doesn't display(or carried over) to the next Activity(ViewActivity.java) when click Save button. I can see the changes on the EditText fields if go back to the EditActivity page.

EditActivity.java

btnSave.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            // starting background task to update request
            new SaveRequestDetails().execute();
        }
    });

    class SaveRequestDetails extends AsyncTask<String, String, String> {


    protected String doInBackground(String... args) {

        // getting updated data from EditTexts
        String request_title = txtTitle.getText().toString();
        String request_date = txtSdate.getText().toString();
        String reqEndDate = txtEdate.getText().toString();
        String hours = txtHours.getText().toString();
        String reason = txtReason.getText().toString();
        String explanation = txtExp.getText().toString();


        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair(TAG_ID, request_id));
        params.add(new BasicNameValuePair(TAG_TITLE, request_title));
        params.add(new BasicNameValuePair(TAG_SDATE, request_date));
        params.add(new BasicNameValuePair(TAG_EDATE, reqEndDate));
        params.add(new BasicNameValuePair(TAG_HOURS, hours));
        params.add(new BasicNameValuePair(TAG_REASON, reason));
        params.add(new BasicNameValuePair(TAG_EXP, explanation));


        JSONObject json = jsonParser.makeHttpRequest(url_update_request,
                "POST", params);


        try {
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {

                Intent i = getIntent();
                // send result code 100 to notify about request update
                setResult(100, i);
                finish();
            } else {

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

ViewActivity.java

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_request);

        Intent i = getIntent();

        // getting request id (rid) from intent
        request_id = i.getStringExtra(TAG_ID);

        // Getting complete request details in background thread
        new GetRequestDetails().execute();

        btnEdit = (Button) findViewById(R.id.btnEdit);

        btnEdit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                // Starting new intent
                Intent in = new Intent(getApplicationContext(), EditActivity.class);
                // sending rid to next activity
                in.putExtra(TAG_ID, request_id);
                startActivity(in);

            }
        });

    }

    // Response from Edit Activity
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // if result code 100
        if (resultCode == 100) {
            // if result code 100 is received 
            // means user edited/deleted request
            // reload this screen again
            Intent intent = getIntent();
            finish();
            startActivity(intent);
        }

    }
user1466971
  • 111
  • 3
  • 9
  • Am curious - why did you delete this question [Updated data doesn't display on next Activity screen](http://stackoverflow.com/questions/11782975/updated-data-doesnt-display-on-next-activity-screen?utm_source=twitterfeed&utm_medium=twitter) - deja vu.... Oo – t0mm13b Aug 02 '12 at 19:18
  • thought I needed to deleted it..^^ – user1466971 Aug 02 '12 at 19:25
  • no worries there! :) just I saw the tweets for Android questions on SO and thought - "Hmmm... that question looks familiar" :) – t0mm13b Aug 02 '12 at 20:05

1 Answers1

3

Your headline says that, that onActivityResult() does not get called.

Use startActivityForResult(in, 55) instead of startActivity(in)

//EDIT: By the way, checking the result code should by done using the RESULT_OK / RESULT_CANCELED constants. You might also consider checking the request code (in my example code it would be 55)

Johannes Staehlin
  • 3,680
  • 7
  • 36
  • 50