Android: How to start/launch a new Activity

Android FAQ: How do I start a new Activity in Android?

You can start a new Activity in Android like this:

startActivity(new Intent(this, ProjectsActivity.class));

This assumes your current class extends one of the Android Activity classes, which gives you access to the startActivity method. In the class I took this example from, my class extends the Android ListActivity class, like this:

public class ProjectsActivity 
extends ListActivity {

Modifying an Intent before starting an Activity

As you can see in that example, you pass an Intent object to the startActivity method. Sometimes you'll want to modifying your Intent object before calling startActivity, and in those cases, you can build your Intent first, and then start your activity, like this:

Intent intent = new Intent(getApplicationContext(), ProjectsAddActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

As you can see, the process is still the same, I'm passing an Intent to the startActivity method, but here I've taken a few extra steps so I can customize my Intent before starting my new Activity.