Wednesday 30 September 2015

Starting Another Activity


To start an activity from one activity we need Intent object and startActivity() method.

Intent:
  • An Intent provides a facility for performing late runtime binding between the code in different applications
  • Its most significant use is in the launching of activities, where it can be thought of as the glue between activities
  • It is basically a passive data structure holding an abstract description of an action to be performed.


Example :

Intent intent = new Intent(FirstActivity.this,SecondActivity.class);

startActivity() ­ Method:

Launch a new activity:

Parameter

  Intent         The description of the activity to start.

This method throws ActivityNotFoundException if there was no Activity found to run the given Intent

Example :

Intent intent = new Intent (FirstActivity.this,SecondActivity.class);
startActivity(intent);


Finish() ­ Method:

Call this when your activity is done and should be closed.
  • If this method called from oncreate method then onDestroy method called immediately.
  • If this method called from onStart method then onStop wil be called and then it will go to onDestroy.



0 comments:

Post a Comment