In this post, you will learn how to create another activity in Android Studio.
When you started the Android Development journey by creating Hello World or any other app. You just filled your First Activity form. But now you want to make another activity, but you don’t know what to do?
Then don’t worry I will help you.
Okay… Actually What is Activity??
In short, Activity is what we have seen in Android apps with the user interface.
Okay, Let’s create a new activity. I assume that you already opened Android Studio and a project.
Step 1 – How to create another Activity in Android Studio
Right click on project package (here com.androidride.createactivity3) in App-> Java. and select New -> Activity -> Empty Activity/Blank activity.
First of all, make sure you are in the Android view in the project explorer. Some views don’t have new activity option. If you are in other views, Just click on the downward arrow and choose Android from the given options.
It’s not a problem if you don’t see Empty Activity option. In older versions of Android studio, you might find Blank activity option. Both of them are the same just a name difference. Don’t use Basic activity now because that’s the advanced version of Empty Activity/Blank activity and contains Floating action button.
- How To Move From One Activity To Another In Android?
- Want to make a WebView Browser???
- Easiest way to make ListView in Android
- What is Support library and How to add it in your project?
- Just Create a class file and extend with Activity or AppCompatActivity.
- Implement onCreate(Bundle savedInstanceState) method.
- Make a layout file
- Show layout file using setContentView() method
- Add <activity> element in AndroidManifest.xml. Otherwise, you may end with ActivityNotFoundException.
Step 2
Enter the Activity name and click Finish.
Enter your activity name, at the same time layout layout name automatically fills up for you if Generate layout file checkbox is checked.
Then Backwards compatibility(AppCompat) option will give the app a certain look in almost all devices, at the same time your activity will extend AppCompatActivity class. For a beginner like you, you can leave the option as empty that cause your activity to extend Activity class and Click Finish.
Your activity files are created. congrats…
You can also create another activity in the Android Studio using the File menu option.
File -> New -> Activity -> Empty Activity & step 2.
But the First method will be easy and quick when you are coding…
You can also create Activity by another method. This is more advanced if you are a beginner.
eg: <application>
<activity android:name=".Second_Activity_Name"/>
</application>
Conclusion
One of the main building blocks of the Android app is activity. Activity is a class in Android SDK, at the same time it’s just a screen with the user interface of our app. Creating another activity in Android Studio is really simple. If you are a beginner or comes from eclipse, you can easily make a new activity without confusing through the above steps. I think this post might have helped you. If you found anything useful, please share it.
Reference
How to create the second activity in Android Studio – docs