Sodapdf
Sodapdf
Sodapdf
We know that, JAVA and its programming tools- techniques can be used in developement of Android Ap
ps.
To develope the android apps : Android studio (SDK), Android IDE (Interective development environment)
, Android tools, etc are used, needed.
Android IDE is used to design the layout of an app where as Android tools (like DEX compiler) compile th
e source code and checks the dependencies, resources, and then generate an APK (Android package file
).
Android studio (SDK) is a software framwork that allows the developer to create/build his/her own android
app’s.android studio itself contains IDE and several tools in integrated format to build the app’s (APK files
).
APK file comprises all the contents of the app. Each app runs on emulator or vitrual machine (DVM). so th
at, at run time, the app will be inaccessible from other apps, each app is local. an APK can comprise one
or more app.
After building an app, android studio itself constructs/generate the coding framework for that app, which c
ontains several in-built components (in the from of classes). All the components are associted with the ma
nifest file AndroidManifest.xml which defines each component of the application and way of interact.
At run time, Android app can access all those components which it requires to do its work.
-There are following four main components that are generated by android studio/framework within an app
(Android application) -
1.Activities
2.Services
3.Broacast Receivers
4.Content Provider
1. Activities
An activities represents a single screen with a user interface. (An Activity component is nothing but a singl
e screen that views the information, results as per the user’s request).
in-short activity component performs (and views) the actions of an app into screen.
For example : In an email application -
An email application might have one activity that shows a list of new emails, another activity to compose a
n email, and another activity for reading emails. if an application has more than one activity, then one of th
em should be marked as the default activity that is presented when the application is launched.
In Android app : An activity component is implemented as a subclass of Activity class as follows -
Where "MainActivity" is name of the newly created activity component, that is created as class.
2. Services
A service component runs in the background when performing long-running operations / task.
For example, a service might play music in the playground while the users is in a different application, or it
might fetch data over the network without blocking user interction with an activity.
In Adroid app : the service (service component) is implemented as a subclass of Service class as follows
-
public class MyService extends Service{
}
Where "MyService" is name of newly created service component, creatd as class.
3. Broadcast Receivers
Broadcast receiver component simply respond to broadcasted messages from other application or the sy
stem.
For example, application can also initiate broadcast to let other applications know that some data has bee
n downloaded to the device and is avaiable for them to use, so this is broadcast receiver who will intercep
t this communication and will initiate appropriate action.
In Android app : A broadcast reciver component is implemented as a subclass of BroadcastReciver class
and each message is broadcast as an intent object -
Where "MyReceiver" is the name of newly created broadcast receiver component, in the from of class.
4. content Providers
A content provider component supplies data from one application to other on request. such request are h
andled by the methods of the ContentResolver class. The data (which is to supply from other application t
o current application) may be stored in the file system, the database or somewhere else entirely.
In Andrid app : content provider component is implemented as a subclass of ContentProvider class in fol
lowing format and also the content provider must have to implement a standard set of API’s that enable ot
her applications to perform transactions (It is implemented through onCreate() method).
Where "MyContentProvider" is created as content provider component in the from of class, which content
s onCreate() method through which content provider component implements to several standard APIs to
enable them to perfrom their transactions so that the desired data will be supplied towards current applica
tion.
What is UI Component ?
---------------------------------
UI means User Interface.
UI components are nothing but set of pre-defined classes that works as structural part of android applicati
on framework that enables to interact with the mobile users. to provide mobile servicess.
For Example : Activities, services, BroacastReceivers, ContentProvider, etc are UI components.
2. Views: UI elements that are drawn on-screen including buttons,lists froms etc.
3. Layouts : View hierarchies that control screen format and appearance of the views.
1. Java
This directory contains the .java source file of an android project. By default, it includes MainActivity.java
source file having an Activity class that runs when your app is launched.
2. res/drawable-hdpi
This directory contains the drawable object that are designed for high-density screens.
3. res/layout
This directory contains the layout of various components that defines an user interface of an app.
4. res/values
This directory contains the references of XML files and strings values related resources.
5. AndroidManifest.xml file
This manifest file describes the fundamental characteristic of the app and also defines in-built component
s of an app.
6. Build.gradle file
This is an auto generated file by an android project which contains compileSdkVersion, buildToolsversio
n, applicationID, minSdkVersion, targetSdkVersion, versionCode and versionName.
After constructing the android app, the Android project stores the data/information related to android app
into following four application files. such application file are created by Android Project itself and stored int
o project file.
package com.example.helloworld;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{
@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
-Here R.layout.activity_main refers to the activity_main.xml file located in the res/layout folder. The onCre
ate() method is one of many method that are figured when an activity is loaded.
- Whatever component (customized UI component like textfield, button, list, radio button, check boxes, etc
) you develop as a part of your application, you must declar all its component in a manifest.xml which resi
des at the root of the application project directory. This file works as an interface between Android OS and
you application, so if you do not declare your component in this file, then it will not be considered by the
OS.
For example, a default manifest file will look like as following file -
<?xml version="1.0"encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android 7.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportRtl="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>
- Here <application>....</application> tags enclosed the component realated to the application. Attribute a
ndroid:icon will point to the application icon available under res/drawable-hdpi.The application uses the im
age named ic_launcher.png located in the drawable folder.
- The <activity> tag is used to specify an activity and android:name attribute specifies the fully qualified cl
ass name of the Activity subclass and the android:label attribute specifies a string to use as the label for t
he activity. You can specify multiple activities using <activity> tags.
-The action for the intent filter is named android.intent.action.MAIN to indicate that this activity serves as t
he entry point for the application. The category for the intent-filter is named android.intent.category.LAUN
CHER to indicate that the application can be launched from the device’s launcher icon.
- The @string refers to the string.xml files explained below. Hence, @string/app_name refers to the app_
name string defined in the string.xml file, which is "HelloWorld". similar way, other strings get populated in
the application.
-following is the list of tags which you will use in your manifest file to specify different Android application c
omponent -
<activity>elements for activities.
<service>elements for services.
<receiver>elements for broadcast receivers.
<provider>elements for content providers.
The String.xml file is located in the res/values folder and it contains all the text that your application uses.
For Example, the names of button, labels, default text, and similar type of strings go into this file.This file i
s responsible for their textual content. For example, a default string file will look like as following file -
<resources>
<string name="app_name">HelloWorld</string>
<string name="hello_world">HelloWorld!</string>
<string name="menu_settings">Setting</string>
<string
name="title_activity_main">MainActivity</string>
</resources>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
toolscontext=".MainActivity"/>
</RelativeLayout>
This is an example of simple RelativeLayout which are will study in a seperate chapter. The TextView is a
n Android control used to build the GUI and it have various attributes like android:layout_width, android:la
yout_heightetc which are being used to set its width and height etc.. The @string refers to the string.xml f
ile located in the res/values folder. Hence, @string/hello_world refers to the hello string defined in the stri
ng.xml file, which is "Hello World!".
------------------------------------
There are number of Ul controls provided by Android that allow you to build the graphical user interface fo
r your app.
1.TextView
This control creates a text field to display the text to the user.
2. EditText
EditText is a predefined subclass of TextView that includes rich editing capabilities.
3. AutoCompleteTextView
The AutoCompleteTextView is a view that is similar to EditText, except that it shows a list of completion s
uggestions automatically while the user is typing.
4.
Button
This control creates a push-button that can be pressed, or clicked, by the user (at run time) to perform an
action.
5 ImageButton
This control creates, shows an image button with an image (instead of text) that can be pressed or clicked
by the user.
6.
CheckBox
This control creates one or more check box elements/options, each have two states i.e. ON and OF. at ru
n time, check boxes can be toggled by the user can select/deselect one or more check box options. it is m
ultichoice control.
You can use this control to provide multipal option to the user and allow to select one or more from them.
7.ToggleButton
This control creates an on/off button with a light indicator.
8. RadioButton
This control creates one or more radio button elements/options, from which user can select only one at ru
n time.
The RadioButton has two states: either checked or unchecked.
You can use this control to provide multipal options to the user and allow to select only one from them.
9.
RadioGroup
This control creates RadioGroup element to groups more than one radio button elements together.
10. ProgressBar
The ProgressBar view provides visual feedback about some ongoing tasks, such as when you are perfor
ming a task in the background
.
11.
Spinner
This control creates a drop-down list element that contains more than one values and allow the user to sel
ect only one value, at run time.
12.
TimePicker
The TimePicker view enables users to select a time of the day, in either 24-hour mode or AM/PM.mode.
13. DatePicker
The DatePicker view enables users to select a date of the day.