Search code examples
androidandroid-activityback-button

on back button previous activity won't get updated with new data


I have two activities profile_Activity and Edit_Profile_activity when I am moving from Profile_Activity to Edit_Profile_activity and doing some changes on profile and update the profile, Activity updates successfully but updated values are not shown on profile_Activity when the back button of mobile is pressed. also the value is shown on press UpEnabled button.


Solution

  • start activity by using

    Intent intent = new Intent(mActivity, Edit_Profile_activity.class);
     startActivityForResult(intent, REQUEST_CODE);
    
    
     @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            switch (requestCode) {
                case REQUEST_CODE:
                     if (resultCode == Activity.RESULT_OK && data!=null) {
                        String abc=data.getStringExtra("data_key")    ;            
                       //write your code for update info
                    }
                    break;
            }
        }
    

    In your Edit_Profile_activity return result by using

    Intent intent=new Intent();
    intent.putExtra("data_key",value);
    setResult(Activity.RESULT_OK, intent);
    finish();