-4

I want to make a app quite similar to contacts app. In the first activity, I want to show my contact list and I have done this. First Activity consists of add new button in which on the click of that button, I want that user enter first and last name and upload an image for the same. I don't know how to navigate between activities so that i get the required answer. Can anyone please help me..?? See the first Activity at: http://postimg.org/image/996iwj5dp/9c92bd46/ and Second Activity at: http://postimg.org/image/wuscpv1tx/fe6f13c4/

on Second activity there is also a button which will make user able to choose a picture from Gallery and thats acts as 3rd Activity. I get confused in getting data from these activities.

1 Answers1

0

You need to implement startActivityforResult() method in first activity. Follow below steps to perform the operation:

1) On click of the Add new button in your First activity, instead of calling startActivity(), call startActivityforResult() using a unique activity code: i.e: public static final int FIRST_ACTIVITY_CODE = 0;

In OnClickListener, you need to implement,

Intent m_data = (FirstActivity.this,SecondActivity.class);
m_data.putextra(//any extra data);
startActivityforResult(FIRST_ACTIVITY_CODE,data);

2) Now when you have added another user from the second activity and you want to pass some data from SecondActivity to FirstActivity, then follow below procedure: Before you finish the SecondActivity after saving the data,

Intent m_data = getIntent();
m_data.putExtra(//data to pass in FirstActivty);
m_data.putExtra(//data to pass in FirstActivty);
.
.
.
setResult(RESULT_OK,m_data);
finish();

3) In the onActivtyResult() of the FirstActivty, do below procedure:

@Override
    protected void onActivityResult(int p_requestCode, int p_resultCode, Intent p_data)
    {
        if(p_requestCode == FIRST_ACTIVITY_CODE && p_resultCode == RESULT_OK)
        {
            NewData = p_data.getExtras().get(//your data);
            // update data 
        }
        super.onActivityResult(p_requestCode, p_resultCode, p_data);
    }

Hope this helps you.