Blog Archive

Android how to Close an Activity Programatically

You need to call method finish(). Here is an example...
 Button nextActivity = (Button) findViewById(R.id.button1);
 nextActivity.setOnClickListener(new View.OnClickListener() {
  public void onClick(View view) {

   Bundle b = new Bundle();
   EditText myName = (EditText) findViewById(R.id.myName);
   b.putString("myName", myName.getText().toString());
   
   //Add the set of extended data to the intent and start it
   Intent intent = new Intent();
   intent.putExtras(b);
   setResult(RESULT_OK,intent);       
   finish();
  }
 });