Android Studio – Creating Basic Activity Project
How to Create a Project in android studio with Basic Activity template.
This is tutorial for beginners to see how to create an android project based on the basic template.
Here’s the process:
- First create a new project in android studio. Go to File –> New Project.
- Type the application name and choose the company name.
- Choose minimum SDK.
- Choose Basic activity.
- Click Finish.
Basic activity will have a toolbar and floating action button already added in the layout
Normally two layouts get generated with this option:
|1.||activity_main.xml||XML Layout||Will get inflated into MainActivity Layout.Typically contains appbarlayout with toolbar.Also has a floatingactionbutton.|
|2.||content_main.xml||XML Layout||Will be included into activity_main.xml.You add your views and widgets here.|
In this example I used a basic activity.
The activity will automatically be registered in the android_manifest.xml. Android Activities are components and normally need to be registered as an application component.
If you’ve created yours manually then register it inside the
<application>...<application> as following, replacing the
MainActivity with your activity name:
<activity android_name=".MainActivity"> <intent-filter> <action android_name="android.intent.action.MAIN" /> <category android_name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
You can see that one action and category are specified as intent filters. The category makes our MainActivity as launcher activity. Launcher activities get executed first when th android app is run.
Advantage of Creating Basic Activity project
You can optionally choose empty activity over basic activity for this project.
However basic activity has the following advantages:
|1.||Provides us a readymade toolbar which gives us actionbar features yet easily customizable|
|2.||Provides us with appbar layout which implements material design appbar concepts.|
|3.||Provides a FloatinActionButton which we can readily use to initiate quick actions especially in examples like these.|
|4.||Decouples our custom content views and widgets from the templating features like toolbar.|
Generated Project Structure
AndroidStudio will generate for you a project with default configurations via a set of files and directories.
Here are the most important of them:
||A directory containing resources that have been compiled from the building of application and the classes generated by android tools. Such a tool is the
||To hold libraries we use in our project.|
||To hold the source code of our application.This is the main folder you work with.|
||Contains our java classes organized as packages.|
||Contains our project resources folders as follows.|
||Contains our drawable resources.|
||Contains our layout resources.|
||Contains our menu resources XML code.|
||Contains our values resources XML code.These define sets of name-value pairs and can be strings, styles and colors.|
||This file gets autogenerated when we create an android project.It will define basic information needed by the android system like application name,package name,permissions,activities,intents etc.|
||Gradle Script used to build the android app.|