title: onBackPressed function in android
body: <p>I am creating app, in one class it contains imageview and textview, another contain edittext, when I press back button, the edittext in 2nd class has to store and set it in textview of first class. Here is my code.</p>
  
  <p>BuckMain.java</p>
  
  <pre><code>package com.jumoun.ibuck;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.view.View;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class BuckMain extends Activity {
  
      ImageView ivSu;
      TextView tvName;
  
      private String sSuName;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          ivSu = (ImageView) findViewById(R.id.ivSu);
          tvName = (TextView) findViewById(R.id.tvName);
          ivSu.setClickable(true);
  
          ivSu.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent();
                  intent.setClass(getApplicationContext(), BuckDisplay.class);
                  startActivityForResult(intent, 1);
              }
          });
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          // TODO Auto-generated method stub
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == 1) {
              if (resultCode == RESULT_OK) {
                  sSuName = data.getStringExtra("name");
                  tvName.setText(sSuName);
              }
          }
      }
  }
  </code></pre>
  
  <p>BuckDisplay.java</p>
  
  <pre><code>    package com.jumoun.ibuck;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.widget.EditText;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class BuckDisplay extends Activity {
  
      ImageView ivSu1;
      TextView tvDisplay;
      TextView tvName1;
      EditText etName1;
      String sName1;
  
      private int resultCode = 1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.buck_display);
          ivSu1 = (ImageView) findViewById(R.id.ivSu1);
          tvDisplay = (TextView) findViewById(R.id.tvDisplay);
          tvName1 = (TextView) findViewById(R.id.tvName1);
          etName1 = (EditText) findViewById(R.id.etName1);
      }
  
      @Override
      public void onBackPressed() {
          // TODO Auto-generated method stub
          super.onBackPressed();
          sName1 = etName1.toString();        
          Bundle bundle = new Bundle();
          bundle.putString("name", sName1);
          Intent intent = new Intent();
          setResult(resultCode, intent);
          intent.putExtras(bundle);
          super.onBackPressed();
      }
  }
  </code></pre>
  
  <p>When I press back button, it is not showing in first class :(</p>