View RSS Feed

Android Developer

Starting an Android Activity

Rate this Entry
by , 02-11-2012 at 10:53 AM (819 Views)
startActivity() method is called when a new activity is started. Intent object is passed as parameter and it describes your activity. What actions you want to perform are described by this intent. Also data used by an activity is carried by this intent.

For launching a new activity, create an intent that describes the activity using the class name. Following code explains how one activity can start a new activity.

Java Code: This is the code to create a new Intent
Intent intent = new Intent(this, SignInActivity.class);
startActivity(intent);
There are cases in which you want to perform different actions like:

  • Send email
  • Text message
  • Status update


In such situation, you can leverage the activities. These are provided by different applications on the device. You need to create an intent that describes the action for your activity and system will launch the activity from required application. In case of more than one activity, user can select the most suitable option.

To send an email message, following intent is created.

Java Code: This is the code to set and start activity
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, recipientArray);
startActivity(intent);
In the above code snippet, EXTRA_EMAIL is added which is a string array of email addresses. Email will be send to these addresses. In response to this intent, an email application will read the string array and will place these addresses into “to” field.

Submit "Starting an Android Activity" to Facebook Submit "Starting an Android Activity" to Digg Submit "Starting an Android Activity" to del.icio.us Submit "Starting an Android Activity" to StumbleUpon Submit "Starting an Android Activity" to Google

Comments