1. Download our Official Android App: Forums for Android!

Apps startActivityForResult ??????

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

  1. aryaxt

    aryaxt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    21
    Joined:
    Jun 1, 2010

    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. IanGClifton

    IanGClifton Well-Known Member
    Rank:
    None
    Points:
    58
    Posts:
    111
    Joined:
    Feb 7, 2010

    You want to do something like

    setResult(RESULT_OK, result);
    finish();

    or

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

    aryaxt Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    21
    Joined:
    Jun 1, 2010

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

Share This Page

Loading...