how to start a new activity in android code example

Example 1: intent android open activity

Intent intent = new Intent(this, DisplayMessageActivity.class);
        intent.putExtra(key:,value:);
        startActivity(intent);

Example 2: intent jump to new activity

//Intent i = new Intent(getApplicationContext(), Second.class);
               // startActivity(i);

Example 3: android start new Activity from an activity with a child

val newIntent = Intent(this@Activity1, Activity2::class.java)
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

this@Activity1.startActivity(newIntent)

Tags:

Java Example