Skip to main content

Points to Remember Before Coding First Application - ABNHive

We need to remember some points before code Android Apps. The points are given below.


  • Package - A package is a namespace. A package is essentially the directory (folder) to which source code belongs. Normally, this is a directory structure that uniquely identifies your application; such as com.helloworld.app. Then you can create packages within your application package that separates your code; such as com.helloworld.app.ui or com.helloworld.app.data. It basically lets you have two classes named Employee if they are in different packages.
  • Class - A class is a blueprint for creating objects in class-based object-oriented programming; you should learn the basics of OOP and understand what an object is, what a class is, what is inheritance, polymorphism, encapsulation before learning anything else about Java.
  • The basic structure for one of the Android project- 
Let's Explore each file
  • AndroidManifest.xml: This is the Android definition file. It contains information about the Android application such as minimum Android version, permission to access Android device capabilities such as in, internet access permission, ability to use phone permission, etc.
Example :

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.abnhive.helloworld"> 
 <uses-sdk android:minSdkVersion="7" />
<application 
    android:versionCode="1"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
        <intent-filter> 
            <action android:name="android.intent.action.MAIN" /> 
            <category android:name="android.intent.category.LAUNCHER" /> 
        </intent-filter> 
    </activity> 
</application> 
</manifest>  
  • java: This folder contains the Java source files with classes and package files. 
  • res: Here we can store resource files such as pictures, XML files for defining layouts, and so forth. Within this folder, there are additional folders such as Drawable, Layout, and Values.
  • build.gradle: This defines your build configuration that applies to all modules. 

Inside res Folder

  • drawable: A Drawable folder contains resource type files like Bitmap (PNG, JPEG), Nine Patch, Vector (XML), Shape, Layers, States, Levels, and Scale.
  • layout: A layout defines the visual structure for a user interface, such as the UI for an Android application. This folder stores Layout files that are written in XML language. Stay tuned for android layouts article.
Example : 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical" > 
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Hello World" /> 
    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Click Me!" /> 
</LinearLayout> 
  • mipmap: Mipmap folder contains the Image Asset file that can be used in Android Studio application. like Launcher icons, Action bar and tab icons, and Notification icons.
  • colors.xml: contains colour resources of the Android application. Colours are defined in hexadecimal format. 
Example : 

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="colorPrimary">#3ACD7A</color> 
    <color name="colorPrimaryDark">#098B41</color> 
    <color name="colorAccent">#9E3DC1</color> 
</resources> 

  • strings.xml: We can create strings and their names for the application.  The string value is identified by a unique name that can be used in the Android application program
Example : 
<resources> 
    <string name="app_name">ABNHive</string> 
</resources> 
  • styles.xml: contains resources of the theme style in the Android application. We can create our own themes for each segment. 
Example : 
<resources> 
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item> 
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
        <item name="colorAccent">@color/colorAccent</item> 
    </style> 
</resources> 

- Aswin Bhim Nath

      Comments

      Popular posts from this blog

      Shortcuts in Android Studio for Android Developers - ABNHive

      I hope these shortcuts will definitely help you to increase the productivity level. Search for command: cmd + shift + a ( Windows / Linux : ctrl +  shift + a) You just type: close and you’ll get a proper shortcut/command. Choose from the last copy / pastes : cmd +  shift  + v ( Windows / Linux : Ctrl + Shift + v). By default, there are 5 last copy/paste items. Enable mulmulti cursorature: ctrl + g (alt + j for Windows / Linux ). Open a class: cmd + o ( Windows / Linux : ctrl + n). Open any file: cmd + shift + o ( Windows / Linux : ctrl + shift + n) Open symbol:  cmd + option + o ( Windows / Linux : alt + shift + n). Go to implementation: cmd + option + b ( Windows / Linux : ctrl + alt + b). Go to declaration: cmd + b ( Windows / Linux : ctrl + b).  Go to type declaration: control + shift + b ( Windows / Linux : ctrl + shift + b).  Go to super: cmd + u ( Windows / Linux : ctrl + u).  Move between tabs: cmd + shift + [ (move left) o...

      Services in Android - ABNHive

      A service is a component which runs in the background without direct interaction with the user.  A service extends the base class Service . Services run with a higher priority than inactive or invisible activities and therefore it is less likely that the Android system terminates them for resource management. The only reason Android will stop a Service prematurely is to provide additional resources for a foreground component usually an Activity. When this happens, your Service can be configured to restart automatically. You can start a service if it is not running using Context.startService(), connect (bind) to a running service using Context.bindService(), and communicate with the running service through an interface that the service exposes. Each service class must have a corresponding <service> declaration in the AndroidManifest.xml file for its package. Types of Services Bound Service Service which call indefinitely in between activity. An Android component m...

      Essential Guide to Setting up Emulators- ABNHive

      An Android emulator is an Android Virtual Device (AVD) that represents a specific Android device. You can use an Android emulator as a platform to run and test your applications on your PC. Installing Emulator on PC Steps are given below Open SDK Manager from Android Studio, click Tools > SDK Manager. Click SDK Tools section Click to tick Android Emulator and Intel x86 Emulator Accelerator - HAXM Installer (If available) Click OK Button Wait to complete download It will automatically download Android Emulator Creating AVD After downloading the Emulator we need to Create AVD (Android Virtual Device).  Click  Tools > AVD Manager. Click Create New Virtual Device Icon Now choose device  If a download option is there, just click to download Device Image Configure Device Now Android Studio creates AVD Click the green icon to run Emulator - Aswin Bhim Nath