1. Check out our companion app, Forums for Android! Download from Google Play

startActivityForResult ??????

Discussion in 'Application Development' started by aryaxt, Jun 16, 2010.

  1. aryaxt

    aryaxt Member
    Thread Starter
    15

    Jun 1, 2010
    21
    0
    15
    I open a new activity by calling startActivityForResult.
    Inside my SecondActivity class i have an exit button, when the user clicks it i need to close the SecondActivity.
    What method should i call to close SecondActivity?
    I tried calling finish() and finishActivity() on my exitButtonClicked, but it didn't do anything.
    Code (Text):
    1. public class FirstActivity extends Activity {
    2.      public void onCreate(Bundle savedInstanceState) {
    3.      .......
    4.      .......
    5.      Intent i = new Intent(this , SecondActivity.class);
    6.      this.startActivityForResult(i, 1);
    7.      }
    8. }
    Code (Text):
    1. public class SecondActivity extends Activity {
    2.      private void exitButtonClicked()
    3.      {
    4.           //I need to call a method to close this activity
    5.      }
    6. }
    7.  
     

    Advertisement

  2. You want to do something like

    setResult(RESULT_OK, result);
    finish();

    or

    setResult(RESULT_CANCELED, null);
    finish();
     
    aryaxt likes this.
  3. aryaxt

    aryaxt Member
    Thread Starter
    15

    Jun 1, 2010
    21
    0
    15
    thanks setting the result solved the problem
     

Share This Page

Loading...