New Android Syllabus
New Android Syllabus
New Android Syllabus
Android Architecture:
2) Native Libraries:
On the top of linux kernel, their are Native libraries such as WebKit, OpenGL,
FreeType, SQLite, Media, C runtime library (libc) etc.
The WebKit library is responsible for browser support, SQLite is for database,
FreeType for font support, Media for playing and recording audio and video formats.
3) Android Runtime:
In android runtime, there are core libraries and DVM (Dalvik Virtual Machine) which is
responsible to run android application. DVM is like JVM but it is optimized for mobile
devices. It consumes less memory and provides fast performance.
4) Android Framework:
On the top of Native libraries and android runtime, there is android framework. Android
framework includes Android API's such as UI (User Interface), telephony, resources,
locations, Content Providers (data) and package managers. It provides a lot of classes
and interfaces for android application development.
5) Applications:
On the top of android framework, there are applications. All applications such as home,
contact, settings, games, browsers are using android framework that uses android
runtime and libraries. Android runtime and native libraries are using linux kernal.
Experiment-2
By the help of activity, you can place all your UI components or widgets in a single
screen.
The 7-lifecycle method of Activity describes how activity will behave at different
states.
<TextVie
w
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
File: MainActivity.java:
package example;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
@Override protected
void onStart() {
super.onStart();
Log.d("lifecycle","onStart invoked"); }
@Override protected
void onResume()
{
super.onResume();
Log.d("lifecycle","onResume invoked"); }
@Override protected void
onPause() {
super.onPause();
Log.d("lifecycle","onPause invoked"); }
@Override protected
void onStop() {
super.onStop();
Log.d("lifecycle","onStop invoked"); }
@Override protected
void onRestart()
{
super.onRestart();
Log.d("lifecycle","onRestart invoked"); }
@Override protected
void onDestroy() {
super.onDestroy();
Log.d("lifecycle","onDestroy invoked"); } }
Experiment-3:
Write an android program to print the set of alphabets/strings in a linear layout and
use button and Text view to your layout.
File: activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="A B C D E F G H I
J K L M N O P Q R S T U V W X Y Z" android:textColor="#3cff00"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="A B C D E F G H I
J K L M N O P Q R S T U V W X Y Z" android:textColor="#3cff00"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:layout_marginTop="100dp"
android:text="next"/> </LinearLayout>
Main2Activity.java:
File: activity_main.xml
Main2Activity.java: package
com.example.myapplication; import
android.support.v7.app.AppCompatActivity; import
android.os.Bundle; public class Main2Activity extends
AppCompatActivity {
@Override protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2); } }
Experiment-5
Write an android program to switch from one activity to another using Intent. When the
activity is changed disable the use of back button to avoid going to previous activity
Views.
PROCEDURE: Step-1: Create a new project and name it Exp4. Step-2: Open app ->
package -> Exp4.java. In this step we open Exp4.java where we add the code
E4.java:
Open res -> layout -> activity_exp4.xml and add following code: In this step we open
an xml file and add the following code.
Activity_exp4.xml:
Activity_e4.xml:
Write an android program to implement activity life cycle using toast messages with
proper positioning.
PROCEDURE: Step-1: Create a new project and name it Exp1. Step-2: Open app ->
package -> MainActivity.java. In this step we open MainActivity where we add the
following code.
MainActivity.java:
Step-3: Open res -> layout -> activity_main.xml and add following code.
Activity_main.xml:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:textColor="#3cff00"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</LinearLayout>
.-
Experiment-7
</android.support.constraint.ConstraintLayout>
File: MainActivity.java
package example.webview; import
android.support.v7.app.AppCompatActivity; import
android.os.Bundle; import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
File: activity_main.xml Drag the EditText and Button from the pallete, now the
activity_main.xml file will like this: File: activity_main.xml
<RelativeLayout
xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools
" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true
" android:layout_marginTop="118dp"
android:text="Call" />
<EditTex
t
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true
" android:layout_marginTop="25dp"
android:ems="10" />
</RelativeLayout
>
File: Android-Manifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest
xmlns:androclass="http://schemas.android.com/apk/res/android"
package="com.example.phonecall
" android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.CALL_PHONE"
/> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.phonecall.MainActivity"
android:label="@string/app_name" > <intent-filter>
<action android:name="android.intent.action.MAIN"
/>
</manifest>
}); }
Experiment-9
File: activity_main.xml
Create an activity_main.xml file in layout folder containing Scroll View and List
View.
<ListVie
w
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv1"
android:divider="#ad5"
android:dividerHeight="2dp"
android:layout_below="@+id/searchView"/>
<SearchView
android:id="@+id/searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:queryHint="Search Here"
android:iconifiedByDefault="false"
android:layout_alignParentTop="true" />
</RelativeLayout
>
File: MainActivity.java
package com.example.searchview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import
android.widget.ArrayAdapter; import
android.widget.Filter; import
android.widget.ListView; import
android.widget.SearchView; import
android.widget.Toast;
import java.util.ArrayList;
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener()
{
@Override public boolean
onQueryTextSubmit(String query) {
if(list.contains(query))
{
adapter.getFilter().filter(query); }else{
Toast.makeText(MainActivity.this, "No Match found",Toast.LENGTH_
LONG).show();
Write Android program to Get Value from the EditText and Set value to the
TextView.
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="NAME"
android:textSize="20sp"
android:layout_margin="20dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="PASSWORD"
android:layout_marginTop="38dp"
android:layout_below="@+id/textView"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView" />
<EditTex
t
android:id="@+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter Name"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="@+id/editPassword"
android:layout_alignStart="@+id/editPassword" />
<EditTex
t
android:id="@+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" android:hint="Enter
Password" android:inputType="textPassword"
android:layout_alignBottom="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp" />
<Button
android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="20dp"
android:text="SUBMIT" />
<Button
android:id="@+id/buttonReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RESET"
android:layout_alignBaseline="@+id/buttonSubmit"
android:layout_alignBottom="@+id/buttonSubmit"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="143dp"
android:textSize="30sp" />
</RelativeLayout
>
Complete Code for MainActivity.java
package
com.example.MainActivity;
View.OnClickListener() {
@Override public void
onClick(View v) {
String name = editName.getText().toString(); String password =
editPassword.getText().toString(); result.setText("Name:\t" +
name + "\nPassword:\t" + password );
}
});
/*
View.OnClickListener() {
@Override public void
onClick(View v) {
editName.setText("");
editPassword.setText("");
result.setText("");
editName.requestFocus(); } }); } }