How to use Activities in an Android app?

In Android development, Activities are a fundamental component that serves as a single screen within an application where users can interact with the app's data. Each Activity provides a user interface to perform actions or display information. Here's a basic guide on how to use Activities in an Android app.

Creating an Activity

To create a new Activity, you must follow these steps:

  1. Create a new Java class that extends the Activity class.
  2. Override the onCreate() method to set the user interface layout for your Activity.
  3. Declare the new Activity in the AndroidManifest.xml file.

Example of an Activity

class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }

Starting a New Activity

You can start a new Activity using an Intent. Here’s how to do it:

Intent intent = new Intent(CurrentActivity.this, NewActivity.class); startActivity(intent);

Android Activities Android development app components user interface AndroidManifest.xml