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();
  }
 });

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.