To navigate to a new activity in an Android app, you can use the startActivity()
method of the Context
class. The startActivity()
method takes an Intent
object as an argument, which specifies the target activity to start.
Here's an example of how you could use the startActivity()
method to navigate to a new activity in an Android app:
import android.content.Intent; // ... Intent intent = new Intent(this, TargetActivity.class); startActivity(intent);
In this example, the Intent
object is created with the this
context and the TargetActivity
class, which represents the target activity to start. The startActivity()
method is then called with the Intent
object as an argument to start the target activity.
You can also pass additional data to the target activity by using the putExtra()
method of the Intent
object. For example:
intent.putExtra("key", "value");
This will add the extra data "value" with the key "key" to the Intent
, which can be accessed in the target activity using the getIntent()
method.
For more information on starting activities in Android, please refer to the Android documentation:
https://developer.android.com/guide/components/intents-filters#Types