Open next activity to current activity

Sudish Kumar
2 min readFeb 14, 2021

In this tutorial we will learn how to create a new activity and how to open it from the current activity may any activity or activity may be anything (MainActivity.kt, LoginActivity,…..)

There may be multiple activities in the App and for switching one to another activity we need Intent and we can also pass data from one to another activity. Many times we pass data from one to another activity.

There are two types of Intent

  1. implicit gives us information of available components given or provided by the system that is to be invoked or argue or pray. Like we parse a URI for the view web page. It doesn’t specify the component
  2. explicitly specifies components and in this tutorial, we will use it. For more intent, we will learn in another tutorial👨‍🏫📓👨‍🏫📓.

Let’s coding

Step 1

Create a New Project in android studio

Step 2

Creating New Activity

a. Right-click on MainActivity.kt > New > Activity > Empty Activity > right-click or enter

b. After Right-click or Enter

Enter Activity name and click on finish or enter after that wait few seconds you can able to your created activity

3. Use Intent for opening another Activity

//  Intent(this, activityName::class.java)
val intent = Intent(this, NextActivity::class.java)
//now start Activity
startActivity(intent)

That’s all about opening one Activity to another Activity

Open New activity from the fragment

//  Intent(this, activityName::class.java)
val intent = Intent(this, NextActivity::class.java)
//now start Activity
startActivity(intent)

Thank you for reading friends. I hope it’s helpful for you and you learn something new.

--

--

Sudish Kumar

Teach lead, Flutter Developer, Android Developer, Node Js Developer