Professional Documents
Culture Documents
MC Lab File Final For Ashish
MC Lab File Final For Ashish
MC Lab File Final For Ashish
ETIT - 452
VISION
To attain global excellence through education, innovation, research, and work ethics with
the commitment to serve humanity.
MISSION
PRACTICAL RECORD
Branch : ITE
PRACTICAL DETAILS
Aim: Write a WML program to print a formatted Text on the mobile Screen usingvarious tags.
Program:
<?xml version="1.0"?>
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<p>Ruchir Bisht</p>
</card>
</wml>
Output:
Viva Questions:
What is the Use of Wml Decks?
- Deck provides the insertion of the data into one or more cards which is also called aspages.
- Deck interacts with the user and the framework on which the application is beingbuilt.
What is WSDL?
WSDL(Web Service Definition Language) is an XML format for describing network services as a set of endpoints
operating on messages containing either document- oriented or procedure-oriented information.
The operations and messages are described abstractly, and then bound to a concrete network protocol and message
format to define an endpoint.
In WML, variables do not have to be declared explicitly. You can choose a variable name you like and assign a
value to it directly. If you read a variable without assigninga value to it earlier, you will obtain an empty string.
The refresh() function, as suggested by its function name, is used to refresh thecurrent card on the WML
browser. It does not take any arguments:
WMLBrowser.refresh();
Experiment-02
Aim: Write a WML program to connect multiple cards from same desk.
Program:
Page 1:
<?xml version="1.0"?>
"http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<p>
<anchor>Next page
<go href="exp2_MC_2.wml"/>
</anchor>
</p>
</card>
</wml>
Page 2:
<?xml version="1.0"?>
"http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<p>
<anchor>
Prev Page
<prev/>
</anchor>
</p>
</card>
</wml>
Output:
Viva Questions:
What is the use of XML?
XML provides a standard method to access information, making it easier for applications and devices of all kinds
to use, store, transmit, and display data.
Metadata is defined as the data providing information about one or more aspects of thedata; it is used to summarize
basic information about data which can make tracking and working with specific data easier.
HTML WML
HTML refers to Hyper Text MarkupLanguage. WML refers to Wireless MarkupLanguage.
HTML is the markup language forwired WML is the markup language forwireless
communication. communication.
It does not use variable. It makes use of variables.
HTML is applied for desktop WML is applied for wireless devices
computers. i.e. cellular phones, PDAs.
Content is integrated with Content separates from presentation.
presentation.
JavaScript is embedded in the sameHTML file. WML scripts stored in separate file.
The HTML DOM defines a standard way for accessing and manipulating HTML documents. It presents an HTML
document as a tree-structure.The XML DOM defines a standard way for accessing and manipulating XML
documents. It presents an XML document as a tree-structure.
Experiment-03
Aim: Write WML program to display table with three columns Image name, Imageand third column contain
hyperlink to open another card.
Program:
Main Page:
<?xml version="1.0"?>
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<p><b>Image Table</b></p>
<p>
<tr>
<td><b>Image name</b></td>
<td><b>Image</b></td>
<td><b>Image link</b></td>
</tr>
<tr>
<td>Sun</td>
</tr>
<tr>
<td>Earth</td>
<b>Earth</b>
<p>
<anchor>
Prev Page
<prev/>
</anchor>
</p>
</card>
</wml>
<?xml version="1.0"?>
"http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<b>Moon</b>
<p>
<anchor>
Prev Page
<prev/>
</anchor>
</p>
</card>
</wml>
Output:
Viva Questions:
What is the function of WAP Gateway?
A WAP gateway sits between mobile devices using the Wireless Application Protocol(WAP) and the World Wide
Web, passing pages from one to the other much like a proxy. This translates pages into a form suitable for the
mobiles, for instance using theWireless Markup Language (WML).
Distillation is lossy, real time, datatype specific compression. WAP uses distillation to reduce wireless traffic
The UAProf (User Agent Profile) specification is concerned with capturing capability and preference information
for wireless devices. This information can be used by content providers to produce content in an appropriate format
for the specific device.
WML is called Light wight language since a lightweight markup language designed to meet the constraints of a
wireless environment with low bandwidth and small handheld devices.
Experiment-04
Program:
<?xml version="1.0"?>
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<p>Tutorial Form</p>
<select>
<option value="cse">CSE</option>
<option value="ece">ECE</option>
<option value="it">IT</option>
</select>
</p>
<p>
<select multiple="true">
</select>
</p>
</p>
</card>
Output:
Viva Questions:
What is Push and Pull technique in WAP?
The pull approach for requesting content, meaning the client makes the request for content from the server.
However, WAP also supports the ability to push content fromthe server to the client using the Wireless Telephony
Application Specification (WTA),which provides the ability to access telephony functions on the client device.
MySQL, PostgreSQL, Microsoft SQL Server, Oracle Database store data of WML pages
DTD (Document Type Definition) & DTD defines the structure and the legal elements and attributes of an XML
document.
Experiment-05
Aim: Write a WML program to use the time control and to trigger on pick event.
Program:
Time Control
<?xml version="1.0"?>
"http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<onevent type="ontimer">
<go href="#welcome"/>
</onevent>
<timer value="50"/>
<p>
<a href="#home">Click</a>
</p>
</card>
<p>
</p>
</card>
<p>
</p>
</card>
</wml>
OnPick Event
<?xml version="1.0"?>
"http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<p>Welcome to Tutorials.</p>
<p>
Select a tutorial :
</select>
</p>
</card>
<p>
</p>
</card>
<p>
</p>
</card>
</wml>
Output:
Viva Questions:
Does WAP run over GPRS?
Yes, WAP can be delivered over any WDP-supported bearer, such as GPRS or SMS.
Program:
<?xml version="1.0"?>
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1">
<p>
max example
</p>
<do type="Accept">
</do>
</card>
<card id="card2">
<p>
<br />
<br />
</p>
</card>
</wml>
Max Function
Output:
<?xml version="1.0"?>
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1">
<p>
abs example
</p>
<do type="accept">
</do>
</card>
<card id="card2">
<p>
<br />
Abs Function
Output:
Viva Questions:
What is the function of WMLScript?
- WMLScript is the alternative language of the JavaScript and used to developthe WML pages.
- It is a function and comes under the Wireless Application Protocol (WAP) thatprovides it to be written
for wireless applications.
- It is used for the client side and has many tasks that provide user inputvalidation, generation of error
messages, etc.
- WMLScript provides the scripts to be written in the specific manner that it canprovide the additional
functionality by the user.
- WMLScript is based on the ECMAScript and it is similar to the standardizedversion of the java.
- WML is also known as Wireless Markup Language based on the XML andimplement the WAP.
- WAP is also known as Wireless application Protocol is used for devices thatuses mark-up
languages.
- WML in WMLScript.
- WML document that is used to create an application is called as deck and itprovides way to add
more pages.
- Deck provides the insertion of the data into one or more cards which is alsocalled as pages.
- This also includes the plain HTML files as well with their variants intact in thefile vnd.wap.wml.
What is the process where WML cards request the device to access WAP? –WMLScript
- WML cards are just like pages on the Decks that are used to request theservices on the
device to access WAP.
- WAP gateway acts as a bridge between the mobile device and World Wide Webfor the communication
purpose.
- It provides the pages or cards from one system to another system using theproxy on the WWW.
- The gateways are used to send the WML cards in the form of a form applicableto use in a mobile
device.
What is the process of adding the client-side logic to WAP using WMLScript?
- WMLScript is similar to the JavaScript and it provides the same feature asJavaScript.
- The standardization is being provided using the ECMAScript standard based onWMLScript.
- WMLScript is used with the WAP gateway to provide the logics andimplementation of it in the
mobile devices.
- Mobile devices are used to run and showcase the result of the input that isgiven and written by
the use of WMLScript.
- Mobile devices are supporting XHTML and standards of HTML due toincrease in the processing
power.
- Mobile devices are used for WAP that provides large coverage areas to use theapplications and run it
on many devices.
What is the process of adding the client-side logic to WAP using WMLScript?
- WMLScript is similar to the JavaScript and it provides the same feature asJavaScript.
- The standardization is being provided using the ECMAScript standard based onWMLScript.
- WMLScript is used with the WAP gateway to provide the logics andimplementation of it in the
mobile devices.
What is the purpose of using WMLScript?
- WMLScript is given in the binary form that allows the mobile devices to runthe applications using
the WAP functionality.
- WMLScript provides the validator that can be used to validate the user inputgiven in the form.
- WMLScript provides the advanced functioinality to write and read the codewith the tools
provided by it.
- WMLScript is a weakly typed language that provides no type checking duringthe compile time or the
run time.
- WMLScript uses the data types as follows
- The user defined functions are usually made and declared in different filehaving the extension
as .wmls.
- The format of the function is as follows:function
name (parameters)
{
control statements;
return var;
}
- This function contains some values in the form of parameters and it is beingcalled by using the
filename followed by hash.
- It is represented as: maths.wmls#squar()
- The standard libraries are used for inbuilt functions and their usage that provides a way to use all that
in the programming.
- Float: this is the library that allows the built-in functions to perform the floating point operations The
functions that are uses as follows: sqrt(), round(), pow(), ceil(), floor(), int(), maxFloat(), minFloat(
- String: it is the library that provides the functions for creation and manipulation of strings.The
functions that are uses as follows: length(), charAt(), find(), replace(), trim(), compare(), format(), etc.
Experiment-07
Program:
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include "ns3/core-module.h" #include
"ns3/network-module.h"#include
"ns3/internet-module.h"
#include "ns3/point-to-point-module.h"#include
"ns3/applications-module.h" #include "ns3/olsr-
helper.h"
#include "ns3/ipv4-static-routing-helper.h"#include
"ns3/ipv4-list-routing-helper.h" using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("SimplePointToPointOlsrExample");int
main (int argc, char *argv[])
// Allow the user to override any of the defaults and the above
Output:
Viva Questions:
List of Security Issues in Adhoc Networks?
- The constantly changing nature of the network topology coupled with data transmission in open medium
makes it highly susceptible to attacks.
- Security issues with respect to data confidentiality, availability of systems and applications,
authentication, system integrity are just as threatening as in conventional networks.
- Vulnerabilities can lead to message eavesdropping, injection of fake messages, denial of service attack
or poor monitoring of routing information.
- Adhoc Networks are susceptible to both internal and external attacks.
-
What is Multi Casting?
Multicasting in computer network is a group communication, where a sender(s) send data to multiple receivers
simultaneously. It supports one – to – many and many – to –many data transmission across LANs or WANs.
What is MANET?
MANET stands for "Mobile Ad Hoc Network." A MANET is a type of ad hoc network that can change locations
and configure itself on the fly. For example, A VANET (Vehicular Ad Hoc Network), is a type of MANET that
allows vehicles to communicate with roadside equipment.
Program:
public:
AodvExample ();
// network NodeContainernodes;
NetDeviceContainerdevices;
Ipv4InterfaceContainerinterfaces;private:
void CreateNodes (); void
CreateDevices ();
void InstallInternetStack ();void
InstallApplications ();
};
int main (int argc, char **argv)
AodvExampletest;
AodvExample::AodvExample () :
size (10),
step (100),
bool
void AodvExample::CreateDevices ()
{
void AodvExample::InstallInternetStack ()
{
AodvHelper aodv;
}
50
}
void AodvExample::InstallApplications ()
{
An Adhoc network is a self-organizing multi-hop wireless network, which is independent neither on fixed
infrastructure nor on predetermined connectivity. It is a collection of nodes, which communicate with each other
using radio transmissions. In ad hoc network, there is no base station to act as router.
The hidden terminal problem is known to degrade the throughput of wireless networks due to collisions, while the
exposed terminal problem results in poor performance by wasting valuable transmission opportunities.
What is HiperLAN?
HiperLAN (High Performance Radio LAN) is a wireless LAN standard. HiperLAN/2 can also be used as a home
network and supports a data rate of up to 54 Mbps.
Hybrid Routing Protocol (HRP) is a network routing protocol that combines Distance Vector Routing Protocol
(DVRP) and Link State Routing Protocol (LSRP) features. HRP is used to determine optimal network destination
routes and report network topology data modifications.
Experiment-09
Aim: Make an application of your choice using WML or Android.
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<p>
<b>Phone Book</b>
</p>
<p>
<option value="Ruchir">Ruchir</option>
<option value="Kaushik">Kaushik</option>
<option value="Gaurav">Gaurav</option>
<option value="Bhuvan">Bhuvan</option>
</select>
<br><br>
<go href="Phonebook.wmls#phone()"/>
</do>
</p>
</card>
<p>
Contact Details
</p>
<p>
<b>$(fullname)</b><br>
<b>$(phoneNumber)</b><br>
<b>$(email)</b>
</p>
</card>
</wml>
Phonebook.wmls File:
var a = WMLBrowser.getVar("name");var
username = "Full Name : ";
var email = "Email Id : "; var phone
= "Contact No : ";
if(String.compare(a,"Ruchir")==0) { username =
username + "Ruchir Bisht";email = email +
"ruchir@gmail.com"; phone = phone +
"9998997856";
}
Output:
Viva Questions:
What is an Activity in Android?
An Android activity is one screen of the Android app's user interface. In that way an Android activity is very
similar to windows in a desktop application. An Android app may contain one or more activities, meaning one or
more screens.
Android Package (APK) is the Android application package file format used by the Android operating system,
and a number of other Android-based operating.
What is an Intent?
An Intent in the Android operating system is a software mechanism that allows users to coordinate the functions
of different activities to achieve a task.
The manifest file describes essential information about your app to the Android build tools, the Android operating
system, and Google Play. Among many other things, the manifest file is required to declare the following: The
app's package name, which usually matches your code's namespace.
Experiment No. 10
AIM: Write a Android Program to create list view, grid view and database
connectivity
Introduction: GRID VIEW
In android GridView is a view group that display items in two dimensional scrolling grid (rows
and columns), the grid items are not necessarily predetermined but they are automaticallyinserted
to the layout using a ListAdapter. Users can then select any grid item by clicking on it. GridView
is default scrollable so we don’t need to use ScrollView or anything else with GridView.
Adapter Is Used To Fill Data In Gridview: To fill the data in a GridView we simply use adapter
and grid items are automatically inserted to a GridView using an Adapter which pulls the content
from a source such as an arraylist, array or database. You can read full Adapter tutorial here.
GridView in Android Studio: Gridview is present inside Containers. From there you can drag and
drop on virtual mobile screen to create it. Alternatively you can also XML code to create it.
android:id="@+id/simpleGridView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns="3"/>
Introduction: LIST VIEW
List of scrollable items can be displayed in Android using ListView. It helps you to displaying the
data in the form of a scrollable list. Users can then select any list item by clicking on it. ListView
is default scrollable so we do not need to use scroll View or anything else with ListView.
ListView is widely used in android applications. A very common example of ListView is your
phone contact book, where you have a list of your contacts displayed in a ListView and if you
click on it then user information is displayed.
Adapter: To fill the data in a ListView we simply use adapters. List items are automatically
inserted to a list using an Adapter that pulls the content from a source such as
an arraylist, array or database.
ListView in Android Studio: Listview is present inside Containers. From there you can drag and
drop on virtual mobile screen to create it. Alternatively you can also XML code to create it.
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/simpleListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="abhiandroid.com.listexample.MainActivity">
</ListView>
Introduction: Database Connectivity
SQLite
SQLite is a relational database management system (RDBMS). If most RDBMSs such asMySQL,
Oracle, etc. are standalone server processes, then SQLite is embedded because it is provided in the
form of a library that is linked in applications.
Like other RDBMSs, data is accessed in a SQLite database by using Structured Query Language
(SQL).
Cursor: a class provides access to the results of a database query. Its methods include:
getCount(): returns the number of rows contained within the result set.
move(): moves by a specified offset from the current position in the result set.
get<type>() (such as getInt(), getDouble(), so on): returns the value of the specified <type>
contained at the specified column index of the row at the current cursor position.
SQLiteDatabase: provides the primary interface between the application code and underlying
SQLite database. Its methods include:
query(): performs a specified database query and returns matching results via a Cursor object.
execSQL(): executes a single SQL Statement that does not return result data.
rawQuery(): executes an SQL query statement and returns matching results in the form of a
Cursor object.
SQLiteOpenHelper : is designed to make it easier to create and update databases. Its methods
include:
onCreate(): called when the database is created for the first time.
onUpgrade(): called in the event that the application code contains a more recent database
version number reference.
ContentValues : allows key/value pairs to be declared consisting of table column identifiers and
the values to be stored in each column. Its methods include:
For Example: Creating a Data Application, we have to follow certain steps as follows.
My application will interact with a database named StudentDB.db, which contains a single table
named Student. The Student table schema will look like this:
The application will consist of an activity and a database handler class (MyDBHandler class). The
database handler will be a subclass of SQLiteOpenHelper and will provide an abstract layer
between the underlying SQLite database and the activity class. A third class (Student class) will
need to be implemented to hold the database entry data as it is passed between the activity and the
handler. My application model can be shown in the following figure:
Data Model Class
The Student class contains fields, constructors, and properties as follows:
We create the Student class in the Android Studio by selecting app > java.
Right-click the myfirstdatabase package and selecting New > Java Class.
Type Student in the Name item, maintain the default options, and click the OK button:
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;
Initialize the Database
The database can be initialized in the constructor of the MyDBHandler class. The code of this
constructor looks like this:
Load Data
The result of above SQL statement is a table. We use the rawQuery() method of a SQLiteDatabase
object to implement SQL statement and display result via a Cursor object. The following code will
demonstrate the loadHandler method:
public void
addHandler(Student
student) {
ContentValues values
= new
ContentValues();
values.put(COLUMN_
ID, student.getID());
values.put(COLUMN_NAME,
student.getStudentName());
SQLiteDatabase db =
this.getWritableDatabase();
db.insert(TABLE_NAME, null,
values);
db.close();
}
Controls used in above UI include:
Source Code:
packagecom.example.callingapp;import
android.net.Uri;
import android.os.Bundle;import
android.app.Activity;importandroid
.content.Intent;import
android.view.Menu;import
android.view.View;import
android.view.View.OnClickListener;import
android.widget.Button;import
android.widget.EditText;import
android.widget.ImageButton;
publicclassCallActivityextendsActivityimplementsOnClickListe
ner{ EditTextet1;
ImageButtonbt1;
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);setContentView(R.
layout.activity_call);
et1=(EditText)findViewById(R.id.editText1);
bt1=(ImageButton)findViewById(R.id.imageButton1);bt1.setOnCli
ckListener(this);
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
//Inflatethemenu;thisaddsitemstotheactionbarifitis
present.getMenuInflater().inflate(R.menu.call, menu);
returntrue;
}
@Override
publicvoidonClick(Viewv){
//TODOAuto-generatedmethodstub
//Call aNumber
Stringnumber=et1.getText().toString();
Intentcall=newIntent(Intent.ACTION_CALL);call.setData(
Uri.parse("tel:" + number));startActivity(call);
}
}
Output:
Experiment-12
AIM:Write a program to design a Mailing application.
a. Source Code:
packagecom.example.emailap;
importandroid.os.Bundle;
import android.app.Activity;
importandroid.content.Intent;
import android.view.Menu;import
android.view.View;import
android.view.View.OnClickListener;import
android.widget.EditText;import
android.widget.ImageButton;importa
ndroid.widget.Toast;
publicclassEmailActivityextendsActivityimplements
OnClickListener{EditTextet1,et2,et3;ImageButtonib1;
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);setContentView(R.
layout.activity_email);
et1 = (EditText)
findViewById(R.id.editText1); et2 =
(EditText)
findViewById(R.id.editText2); et3 =
(EditText)
findViewById(R.id.editText3);
ib1=(ImageButton)findViewById(R.id.imageButton1);ib1.setOnCli
ckListener(this);
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
//Inflatethemenu;thisaddsitemstotheaction barifitis present.getMenuInflater().inflate(R.menu.email,
menu);
returntrue;
}
@Override
publicvoidonClick(Viewv){
//TODOAuto-generatedmethodstub
Stringemailid=et1.getText().toString();String[]e
mails ={emailid};
String subject =
et2.getText().toString();Stringmessage=et3.getTe
xt().toString();
Intent email = new
Intent(Intent.ACTION_SEND);email.setType("*/*");email.pu
tExtra(Intent.EXTRA_EMAIL,
emails);email.putExtra(Intent.EXTRA_SUBJECT,subject);em
ail.putExtra(Intent.EXTRA_TEXT,
message);startActivity(email);
Toast.makeText(this,"MailSenttoEmailProvider",Toast.LENG
TH_SHORT).show();
}
}
Experiment-13
AIM: Write a program to display the latitude and longitude of a user Program
MainActivity.java
package com.gpslocationtracker;
import android.support.v7.app.ActionBarActivity; import android.os.Bundle;
import android.view.Menu; import android.view.MenuItem; import android.widget.TextView;
public class MainActivity extends ActionBarActivity
{ TextView textview; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
// check if GPS enabled
GPSTracker gpsTracker = new GPSTracker(this);
if (gpsTracker.canGetLocation())
{
String stringLatitude = String.valueOf(gpsTracker.latitude); textview = (TextView)findViewById(R.id.fieldLatitude);
textview.setText(stringLatitude);
String stringLongitude = String.valueOf(gpsTracker.longitude); textview = (TextView)findViewById(R.id.fieldLongitude);
textview.setText(stringLongitude);
}
else
{
// can't get location
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
gpsTracker.showSettingsAlert();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
return location;
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub return null;
}
}
OUTPUT
Experiment 14
AIM: Write a program to design Multiple Activity Class.
Source Code:
FirstActivity.java
package com.example.multipleactivities; import android.os.Bundle;
import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View;
import android.view.View.OnClickListener; import android.widget.Button;
import android.widget.EditText; import android.widget.Toast;
public class FirstActivity extends Activity implements OnClickListener { EditText et1, et2;
Button bt1;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
bt1.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.first, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}else {
Intent next = new Intent(this, SecondActivity.class); next.putExtra("NAME", name); next.putExtra("NUMBER", number);
startActivity(next);
finish();
}
}
}
a. SecondActivity.java
package com.example.multipleactivities;
super.onCreate(savedInstanceState); setContentView(R.layout.activity_second);
tv1 = (TextView) findViewById(R.id.textView_name); tv2 = (TextView) findViewById(R.id.textView_number);
bt1 = (Button) findViewById(R.id.button_main); bt2 = (Button) findViewById(R.id.button_exit);
bt1.setOnClickListener(this); bt2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub switch(v.getId()){
case R.id.button_main:
Intent main = new Intent(this, FirstActivity.class); startActivity(main); finish(); break;
case R.id.button_exit:
Toast.makeText(this, "Bye !", Toast.LENGTH_SHORT).show(); finish(); break;
}
}
}
Experiment-15
Aim: Write a program to design a contacts application.
SourceCode:
DatabaseActivity.java
packagecom.example.contactsapp;import
android.os.Bundle;
import
android.app.Activity;importand
roid.content.Intent;import
android.view.Menu;import
android.view.View;
import
android.view.View.OnClickListener;import
android.widget.Button;
import
android.widget.EditText;importa
ndroid.widget.Toast;
publicclassDatabaseActivityextendsActivityimplementsOnClickListener{
EditTextet1,et2;
Buttonbt1,bt2,bt3;
@Override
protectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);
setContentView(R.layout.activity_database);
et1 = (EditText) findViewById(R.id.editText1);et2 =
(EditText) findViewById(R.id.editText2);bt1 = (Button)
findViewById(R.id.button_save);bt2=(Button)findViewBy
Id(R.id.button_view);bt3=(Button)findViewById(R.id.butt
on_exit);
bt1.setOnClickListener(this);bt2.setO
nClickListener(this);bt3.setOnClickLi
stener(this);
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
//Inflatethemenu;thisaddsitemstotheaction barifitispresent.
// TODO Auto-generated method stubdb.execSQL("DROPTBALE"+DB_TABLE+";");
db.execSQL(createQuery);
}
}
publicStringread(){
//TODOAuto-generatedmethodstubStringresult= "";
String[]columns={DB_CNAME,DB_CNUMBER};
Cursorc=db.query(DB_TABLE,columns,null,null,null,null,null);
intnameI= c.getColumnIndex(DB_CNAME);
int numberI = c.getColumnIndex(DB_CNUMBER);
result=result+c.getString(nameI)+"-"+c.getString(numberI)+"\n";
}
Return result;
}
}
c) ViewActivity.java
}
}
}