Professional Documents
Culture Documents
1
SYLLABUS
4.1 Menu :Basics, Custom v/s System Menus,
Create and Use Handset menu Button
(Hardware)
4.2 Dialog : Creating and Altering Dialogs
2
5.1 MENU
Options Menu
The primary collection of menu items for an
activity, which appears when the user touches
the MENU button.
Context Menu
A floating list of menu items that appears when
the user touches and holds a view that's
registered to provide a context menu.
Submenu
A floating list of menu items that appears when
the user touches a menu item that contains a 3
nested menu.
Pop-Up Menu : A pop-up menu is a type of menu that pops up
on the screen when the user right-clicks a certain object or area. It
can be also called a contextual menu since the menu options are
relevant to where the user right-clicked on the screen. Pop-up
menus provide quick access to common program functions and
are used by most operating systems and applications.
OPTION MENU
4
1: CREATE XML FOR MENU
<item android:id="@+id/ChangeColor"
android:icon="@drawable/setting"
android:title="Settings" />
<item android:id="@+id/phoneInformation"
android:icon="@drawable/phone"
android:title="My Phone Information" />
<item android:id="@+id/callInfo"
android:icon="@drawable/callinfo"
android:title="In and Out Call Info" />
<item android:id="@+id/email"
android:icon="@drawable/mail"
android:title="Mail to Developer" /> 5
</menu>
2: REGISTER IN ACTIVITY
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options, menu);
return true;
}
6
3: HANDLE CLICK EVENTS
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle item selection
switch (item.getItemId())
{
case R.id.ChangeColor:
// write code to execute when clicked on thisoption
return true;
case R.id.phoneInformation:
// write code to execute when clicked on thisoption
return true;
case R.id.callInfo:
// write code to execute when clicked on thisoption
return true;
case R.id.email:
// write code to execute when clicked on thisoption
return true;
default: 7
return super.onOptionsItemSelected(item);
}
}
4.2 CREATE ALERT DIALOG:
13
Where we use Alert Dialog
• Order Confirm
• Display Error
• Battery Low
• Games Reward Show
• Exit App
• Depends on your app scenario
17
5.3 ANDROID TOAST, LIST AND ADAPTER
Android Toast:
Toast toast=Toast.makeText(getApplicationCont
ext(),"Ur Message",Toast.LENGTH_SHORT);
toast.show();
Here, getApplicationContext() method returns
the instance of Context.
19
EXAMPLE
//Displaying Toast with Hello Javatpoint message
Toast.makeText(getApplicationContext(),"Hello Jav
atpoint",Toast.LENGTH_SHORT).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_main, m
enu);
return true;
} 20
}
21
ANDROID CUSTOM TOAST
25
RIGHT CLICK ON RES/LAYOUT CHOOSE
NEW/OTHER (OR XML IF IT IS THERE)
26
CHOOSE ANDROID/ANDROID XML FILE (NOT JUST
XML FILE) AND CLICK NEXT
27
GIVE THE FILE A NAME – REMEMBER THE FILE NAME CONVENTION SMALL
LETTERS NUMBERS UNDERSCORES AND PERIODS. CHOOSE A ROOT
ELEMENT. CLICK FINISH.
28
RESULTING XML IN GRAPHICAL LAYOUT
VIEW AND XML VIEW
29
CODE FOR STRING ARRAY,
ARRAYADAPTER, AND LISTVIEW
30
RESULT SO FAR IN EMULATOR. NOTE THAT
THE LIST ITEMS ARE CLICKABLE
31
CODE FOR THE
ONITEMCLICKLISTENER
32
RESUL
T
33
5.1 BASIC OPERATIONS OF SQLITEDATABASE
34
INSERT
36
UPDATE
37
VIEW
39
Active processes
include the following:
Activities in an active state — that is, those in
the foreground responding to user events.
Broadcast Receivers executing onReceive event
handlers
Services executing onStart, onCreate,
or onDestroy event handlers
Running Services that have been flagged to run
in the foreground
41
1. ACTIVE PROCESSES
Active (foreground) processes have application
components the user is interacting with.
These are the processes Android tries to keep
responsive by reclaiming resources from other
applications.
There are generally very few of these processes,
and they will be killed only as a last resort.
40
2. VISIBLE PROCESSES
Visible but inactive processes are those hosting
“visible” Activities.
Visible Activities are visible, but they aren’t in
the foreground or responding to user events.
This happens when an Activity is only partially
obscured (by a non-full-screen or transparent
Activity).
There are generally very few visible processes,
and they’ll be killed only under extreme
circumstances to allow active processes to
continue.
42
3. STARTED SERVICE PROCESSES
Processes hosting Services that have been
started.
Because these Services don’t interact directly
with the user, they receive a slightly lower
priority than visible Activities or foreground
Services.
Applications with running Services are still
considered foreground processes and won’t be
killed unless resources are needed for active or
visible processes.
When the system terminates a running Service it
43
will attempt to restart them when resources
become available.
4. BACKGROUND PROCESSES
Processes hosting Activities that aren’t visible
and that don’t have any running Services.
There will generally be a large number of
background processes that Android will kill using
a last-seen-first-killed pattern in order to
obtain resources for foreground processes.
44
5. EMPTY PROCESSES
To improve overall system performance, Android
will often retain an application in memory after it
has reached the end of its lifetime.
Android maintains this cache to improve the
start-up time of applications when they’re
relaunched.
These processes are routinely killed, as required.
45
IMPORTANT
QUESTIONS.
1. Write a short note on Toast .
2. What is menu ? Explain types of menu.
3. Write a short note on option menu.
4. Explain context menu in detail.
5. Write short on Alert Dialog box.
6. What is sqlite database ? and how to create sqlite
database.
7. Explain basic operation of sqlite database.
8. Define cursor in sqlite database.
46