0% found this document useful (0 votes)
36 views25 pages

OOP-Ktunotes - In-Solved QP 2

This document discusses a model examination for an Object Oriented Programming course. It contains questions that assess concepts like procedural vs object oriented programming, operator overloading, inheritance, constructors, pointers, exceptions, and Android application development.

Uploaded by

Arjun S Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views25 pages

OOP-Ktunotes - In-Solved QP 2

This document discusses a model examination for an Object Oriented Programming course. It contains questions that assess concepts like procedural vs object oriented programming, operator overloading, inheritance, constructors, pointers, exceptions, and Android application development.

Uploaded by

Arjun S Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Reg No........................... Name..........................

CO-OPERATIVE ACADEMY OF PROFESSIONAL EDUCATION


VI TH SEMESTER BTECH DEGREE MODEL EXAMINATION MARCH 2018

COURSE CODE: EC312

COURSE NAME: OBJECT ORIENTED PROGRAMMING

MAX MARKS: 100 DURATION: 3 Hours

PART A(Answer any Two)

1. (a) Differentiate between procedural and object oriented programming. (7)


(b) Explain any 5 concepts of OOP (8)

2. (a) What is unary operator overloading? Explain with sample code (7)
(b) What is virtual base class? Explain with sample code (8)

3. (a) Explain three types of constructors (7)


(b)What is inheritance? Explain types of inheritance. (8)

PART B (Answer any two)


4. (a) Explain the concept of pointer to object with sample code (7)
(b) What is method overriding? (8)

5. (a) What is exceptions in java? Give an examples. (8)


(b)Explain Virtual Functions. (7)

6. (a) Explain heirarchical inheritance in java with sample code (8)


(b) What is the concept of pointers in derived class (7)

PART C(Answer any two)

7. (a) Explain building blocks of android (10)


(b) What is Broadcast Receiver, UI components and content providers (10)

8. (a)Explain intents & intent filters (10)


(b)What is android manifest (10)

9. (a) Explain layouts and Drawable Resources with example (10)


(b)Explain styles and themes with example (10)
ANSWERS

1a.

Procedure Object Oriented Programming


Oriented
Programming
Divided Into In POP, program is divided into small parts In OOP, program is divided into parts
called functions. called objects.
Importance In POP,Importance is not given to databut In OOP, Importance is given to the data
to functions as well as sequence of actions rather than procedures or functions because
to be done. it works as a real world.
Approach POP follows Top Down approach. OOP follows Bottom Up approach.
Access Specifiers POP does not have any access specifier. OOP has access specifiers named Public,
Private, Protected, etc.
Data Moving In POP, Data can move freely from In OOP, objects can move and communicate
function to function in the system. with each other through member functions.
Expansion To add new data and function in POP is OOP provides an easy way to add new data
not so easy. and function.
Data Access In POP, Most function uses Global data for In OOP, data can not move easily from
sharing that can be accessed freely from function to function,it can be kept public or
function to function in the system. private so we can control the access of data.
Data Hiding POP does not have any proper way for OOP provides Data Hiding so provides more
hiding data so it is less secure. security.
Overloading
S . I N
In POP, Overloading is not possible. In OOP, overloading is possible in the form

OTE
of Function Overloading and Operator

Examples
K T U N
Example of POP are : C, VB, FORTRAN,
Pascal.
Overloading.
Example of OOP are : C++, JAVA,
VB.NET, C#.NET.

1b.

OOPs – Object Oriented Programming System


Object-oriented programming (OOP) is a programming paradigm that uses “Objects “and their
interactions to design applications and computer programs.

There are different types of OOPs are used, they are


1. Object
2. Class
3. Data Abstraction & Encapsulation
4. Inheritance
5. Polymorphism
6. Dynamic Binding
7. Message Passing

1) Object : Object is the basic unit of object-oriented programming. Objects are identified by its unique
name. An object represents a particular instance of a class. There can be more than one instance of
an object. Each instance of an object can hold its own relevant data.
An Object is a collection of data members and associated member functions also known as methods.
For example whenever a class name is created according to the class an object should be created
without creating object can’t able to use class.

Downloaded from Ktunotes.in


The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have;
the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur;
Lassie has brown-and-white fur.
2) Class :
Classes are data types based on which objects are created. Objects with similar properties and
methods are grouped together to form a Class. Thus a Class represents a set of individual objects.
Characteristics of an object are represented in a class as Properties. The actions that can be
performed by objects become functions of the class and is referred to as Methods.
For example consider we have a Class of Cars under which Santro Xing, Alto and WaganR
represents individual Objects. In this context each Car Object will have its own, Model, Year of
Manufacture, Colour, Top Speed, Engine Power etc., which form Properties of the Car class and the
associated actions i.e., object functions like Start, Move, Stop form the Methods of Car Class.No
memory is allocated when a class is created. Memory is allocated only when an object is created, i.e.,
when an instance of a class is created.

1.

3) Data abstraction & Encapsulation : The wrapping up of data and its functions into a single unit is
called Encapsulation.
When using Data Encapsulation, data is not accessed directly, it is only accessible through the
functions present inside the class.
Data Abstraction increases the power of programming language by creating user defined data types.
Data Abstraction also represents the needed information in the program without presenting the
details.
Abstraction refers to the act of representing essential features without including the background
details or explanation between them.
For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more
components. To build the Car class, one does not need to know how the different components work
internally, but only how to interface with them, i.e., send messages to them, receive messages from

S . I N
them, and perhaps make the different objects composing the class interact with each other.

OTE
4) Inheritance :

N
Inheritance is the process of forming a new class from an existing class or base class.

derived class.
K T U
The base class is also known as parent class or super class, the new class that is formed is called

Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall
code size of the program, which is an important concept in object-oriented programming.
It is classifieds into different types, they are

 Single level inheritance


 Multi-level inheritance
 Hybrid inheritance
 Hierarchial inheritance
5) Polymorphism :
Polymorphism allows routines to use variables of different types at different times. An operator or
function can be given different meanings or functions. Polymorphism refers to a single function or
multi-functioning operator performing in different ways.
Poly a Greek term ability to take more than one form. Overloading is one type of Polymorphism. It
allows an object to have different meanings, depending on its context. When an exiting operator or
function begins to operate on new data type, or class, it is understood to be overloaded.
6) Dynamic binding :
It contains a concept of Inheritance and Polymorphism.
7) Message Passing : It refers to that establishing communication between one place to another.

Downloaded from Ktunotes.in


2a. The unary operators operate on a single operand and following are the
examples of Unary operators −

 The increment (++) and decrement (--) operators.

 The unary minus (-) operator.

 The logical not (!) operator.

The unary operators operate on the object for which they were called and
normally, this operator appears on the left side of the object, as in !obj, -
obj, and ++obj but sometime they can be used as postfix as well like
obj++ or obj--.

Following example explain how minus (-) operator can be overloaded for
prefix as well as postfix usage.

#include <iostream>

using namespace std;

S . I N
OTE
class Distance {

private:

int feet;
K T U N // 0 to infinite

int inches; // 0 to 12

public:

// required constructors

Distance() {

feet = 0;

inches = 0;

Distance(int f, int i) {

feet = f;

inches = i;

Downloaded from Ktunotes.in


// method to display distance

void displayDistance() {

cout << "F: " << feet << " I:" << inches <<endl;

// overloaded minus (-) operator

Distance operator- () {

feet = -feet;

inches = -inches;

return Distance(feet, inches);

};

int main() {

Distance D1(11, 10), D2(-5, 11);


S . I N
T U N OTE
-D1;
K
D1.displayDistance();
// apply negation

// display D1

-D2; // apply negation

D2.displayDistance(); // display D2

return 0;

When the above code is compiled and executed, it produces the following result −
F: -11 I:-10
F: 5 I:-11

Downloaded from Ktunotes.in


2b. #include<iostream.h>
#include<conio.h>

class ClassA
{
public:
int a;
};

class ClassB : public ClassA


{
public:
int b;
};
class ClassC : public ClassA
{
S . I N
public:

T U N OTE
};
int c;
K
class ClassD : public ClassB, public ClassC
{
public:
int d;
};

void main()
{

ClassD obj;

obj.a = 10; //Statement 1, Error occur

Downloaded from Ktunotes.in


obj.a = 100; //Statement 2, Error occur

obj.b = 20;
obj.c = 30;
obj.d = 40;

cout<< "\n A : "<< obj.a;


cout<< "\n B : "<< obj.b;
cout<< "\n C : "<< obj.c;
cout<< "\n D : "<< obj.d;

Output :

A from ClassB : 10
S . I N
A from ClassC : 100

T U N OTE
B : 20
C : 30 K
D : 40

3a. A constructor is a member function of a class which initializes objects of a class.


In C++,Constructor is automatically called when object(instance of class) create.It is
special member function of the class.
How constructors are different from a normal member function?
A constructor is different from normal functions in following ways:
 Constructor has same name as the class itself
 Constructors don’t have return type
 A constructor is automatically called when an object is created.
 If we do not specify a constructor, C++ compiler generates a default constructor for us (expects
no parameters and has an empty body).
Types of Constructors
1. Default Constructors: Default constructor is the constructor which doesn’t take any
argument. It has no parameters.
// Cpp program to illustrate the
// concept of Constructors
#include <iostream>
using namespace std;

Downloaded from Ktunotes.in


class construct
{
public:
int a, b;

// Default Constructor
construct()
{
a = 10;
b = 20;
}
};

int main()
{
// Default constructor called automatically
// when the object is created
construct c;
cout << "a: "<< c.a << endl << "b: "<< c.b;
return 1;
3b. One of the most important concepts in object-oriented programming is that of
inheritance. Inheritance allows us to define a class in terms of another class, which makes it
easier to create and maintain an application. This also provides an opportunity to reuse the
code functionality and fast implementation time.

S . I N
When creating a class, instead of writing completely new data members and member

T U OTE
functions, the programmer can designate that the new class should inherit the members of an

N
existing class. This existing class is called the base class, and the new class is referred to as
the derived class. K
The idea of inheritance implements the is a relationship. For example, mammal IS-A
animal, dog IS-A mammal hence dog IS-A animal as well and so on.

Base and Derived Classes


A class can be derived from more than one classes, which means it can inherit data and
functions from multiple base classes. To define a derived class, we use a class derivation list
to specify the base class(es). A class derivation list names one or more base classes and has
the form −
class derived-class: access-specifier base-class

Where access-specifier is one of public, protected, or private, and base-class is the name of
a previously defined class. If the access-specifier is not used, then it is private by default.

Consider a base class Shape and its derived class Rectangle as follows −

Live Demo #include <iostream>

Downloaded from Ktunotes.in


using namespace std;

// Base class

class Shape {

public:

void setWidth(int w) {

width = w;

void setHeight(int h) {

height = h;

protected:

int width;

int height;
S . I N
};

T U N OTE
// Derived class
K
class Rectangle: public Shape {

public:

int getArea() {

return (width * height);

};

int main(void) {

Rectangle Rect;

Rect.setWidth(5);

Rect.setHeight(7);

Downloaded from Ktunotes.in


// Print the area of the object.

cout << "Total area: " << Rect.getArea() << endl;

return 0;

4a. A pointer to a C++ class is done exactly the same way as a pointer to a structure and to
access members of a pointer to a class you use the member access operator -> operator, just
as you do with pointers to structures. Also as with all pointers, you must initialize the
pointer before using it.

Let us try the following example to understand the concept of pointer to a class −

#include <iostream>

using namespace std;

S . I N
class Box {

T U N OTE
public:
K
// Constructor definition

Box(double l = 2.0, double b = 2.0, double h = 2.0) {

cout <<"Constructor called." << endl;

length = l;

breadth = b;

height = h;

double Volume() {

return length * breadth * height;

private:

double length; // Length of a box

Downloaded from Ktunotes.in


double breadth; // Breadth of a box

double height; // Height of a box

};

int main(void) {

Box Box1(3.3, 1.2, 1.5); // Declare box1

Box Box2(8.5, 6.0, 2.0); // Declare box2

Box *ptrBox; // Declare pointer to a class.

// Save the address of first object

ptrBox = &Box1;

// Now try to access a member using member access operator

cout << "Volume of Box1: " << ptrBox->Volume() << endl;

S . I N
N OTE
// Save the address of first object

T U
ptrBox = &Box2;
K
// Now try to access a member using member access operator

cout << "Volume of Box2: " << ptrBox->Volume() << endl;

return 0;

When the above code is compiled and executed, it produces the following
result −
Constructor called.
Constructor called.
Volume of Box1: 5.94
Volume of Box2: 102

4b. Function Overloading (achieved at compile time)

Downloaded from Ktunotes.in


It provides multiple definitions of the function by changing signature i.e changing
number of parameters, change datatype of parameters, return type doesn’t play
anyrole.
 It can be done in base as well as derived class.
 Example:
 void area(int a);

 void area(int a, int b);

// CPP program to illustrate


// Function Overloading
#include <iostream>
using namespace std;

// overloaded functions
void test(int);
void test(float);
void test(int, float);

int main()
{
int a = 5;
float b = 5.5;

// Overloaded functions
// with different type and
// number of parameters

S . I N
OTE
test(a);
test(b);
test(a, b);

return 0; K T U N
}

// Method 1
void test(int var)
{
cout << "Integer number: " << var << endl;
}

// Method 2
void test(float var)
{
cout << "Float number: "<< var << endl;
}

// Method 3
void test(int var1, float var2)
{
cout << "Integer number: " << var1;
cout << " and float number:" << var2;
}
Run on IDE
Output:

Integer number: 5

Downloaded from Ktunotes.in


Float number: 5.5

Integer number: 5 and float number: 5.5

5a. Exceptions in Java


An exception is an unwanted or unexpected event, which occurs during the execution of a program i.e
at run time, that disrupts the normal flow of the program’s instructions.
Error: An Error indicates serious problem that a reasonable application should not try to catch.
Exception: Exception indicates conditions that a reasonable application might try to catch.
Exception Hierarchy
All exception and errors types are sub classes of class Throwable, which is base class of
hierarchy.One branch is headed by Exception. This class is used for exceptional conditions that
user programs should catch. NullPointerException is an example of such an exception.Another
branch,Error are used by the Java run-time system(JVM) to indicate errors having to do with the
run-time environment itself(JRE). StackOverflowError is an example of such an error.

S . I N
T U N OTE
K

5b. Virtual Function in C++


A virtual function a member function which is declared within base class and is re-defined (Overriden)
by derived class.When you refer to a derived class object using a pointer or a reference to the base
class, you can call a virtual function for that object and execute the derived class’s version of the
function.
 Virtual functions ensure that the correct function is called for an object, regardless of the type of
reference (or pointer) used for function call.
 They are mainly used to achieve Runtime polymorphism

Downloaded from Ktunotes.in


 Functions are declared with a virtual keyword in base class.
 The resolving of function call is done at Run-time.
Rules for Virtual Functions
1. They Must be declared in public section of class.
2. Virtual functions cannot be static and also cannot be a friend function of another class.
3. Virtual functions should be accessed using pointer or reference of base class type to achieve
run time polymorphism.
4. The prototype of virtual functions should be same in base as well as derived class.
5. They are always defined in base class and overridden in derived class. It is not mandatory for
derived class to override (or re-define the virtual function), in that case base class version of
function is used.
6. A class may have virtual destructor but it cannot have a virtual constructor.
Compile-time(early binding) VS run-time(late binding) behavior of Virtual
Functions
Consider the following simple program showing run-time behavior of virtual functions.
// CPP program to illustrate

// concept of Virtual Functions

#include<iostream>

using namespace std;

class base

S . I N
public:

T U N OTE
K
virtual void print ()

{ cout<< "print base class" <<endl; }

void show ()

{ cout<< "show base class" <<endl; }

};

class derived:public base

public:

void print ()

{ cout<< "print derived class" <<endl; }

Downloaded from Ktunotes.in


void show ()

{ cout<< "show derived class" <<endl; }

};

int main()

base *bptr;

derived d;

bptr = &d;

//virtual function, binded at runtime

bptr->print();

// Non-virtual function, binded at compile time

bptr->show();

S . I N
}

T U N OTE
Output:
K
print derived class

show base class

6A
1. class Employee{
2. float salary=40000;
3. }
4. class Programmer extends Employee{
5. int bonus=10000;
6. public static void main(String args[]){
7. Programmer p=new Programmer();
8. System.out.println("Programmer salary is:"+p.salary);
9. System.out.println("Bonus of Programmer is:"+p.bonus);
10. }
11. }

Downloaded from Ktunotes.in


7a. Android Core Building Blocks

An android component is simply a piece of code that has a well defined life cycle e.g.
Activity, Receiver, Service etc.

The core building blocks or fundamental components of android are activities,


views, intents, services, content providers, fragments and AndroidManifest.xml.

Activity

S . I N
T U N OTE
An activity is a class that represents a single screen. It is like a Frame in AWT.

View
K
A view is the UI element such as button, label, text field etc. Anything that you see is a
view.

Intent

Intent is used to invoke components. It is mainly used to:

o Start the service

o Launch an activity
o Display a web page
o Display a list of contacts

o Broadcast a message

o Dial a phone call etc.

For example, you may write the following code to view the webpage.

1. Intent intent=new Intent(Intent.ACTION_VIEW);

Downloaded from Ktunotes.in


2. intent.setData(Uri.parse("http://www.javatpoint.com"));
3. startActivity(intent);

Service

Service is a background process that can run for a long time.

There are two types of services local and remote. Local service is accessed from within the
application whereas remote service is accessed remotely from other applications running on the same
device.

Content Provider

Content Providers are used to share data between the applications.

Fragment

S . I N
OTE
Fragments are like parts of activity. An activity can display one or more fragments on the screen at the
same time.

K T U N
AndroidManifest.xml

It contains informations about activities, content providers, permissions etc. It is like the web.xml file
in Java EE.

Android Virtual Device (AVD)

It is used to test the android application without the need for mobile or tablet etc. It can be created in
different configurations to emulate different types of real devices.

7b. Broadcast Receivers simply respond to broadcast messages from other applications or from the
system itself. These messages are sometime called events or intents. For example, applications can
also initiate broadcasts to let other applications know that some data has been downloaded to the
device and is available for them to use, so this is broadcast receiver who will intercept this
communication and will initiate appropriate action.

There are following two important steps to make BroadcastReceiver works for the system
broadcasted intents −

Downloaded from Ktunotes.in


 Creating the Broadcast Receiver.

 Registering Broadcast Receiver

There is one additional steps in case you are going to implement your custom intents then you will
have to create and broadcast those intents.

Creating the Broadcast Receiver


A broadcast receiver is implemented as a subclass of BroadcastReceiver class and overriding the
onReceive() method where each message is received as a Intent object parameter.

public class MyReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();

Registering Broadcast Receiver

S . I N
OTE
An application listens for specific broadcast intents by registering a broadcast receiver

K T N
in AndroidManifest.xml file. Consider we are going to register MyReceiver for system generated

U
event ACTION_BOOT_COMPLETED which is fired by the system once the Android system has
completed the boot process.

BROADCAST-RECEIVER

<application

android:icon="@drawable/ic_launcher"

Downloaded from Ktunotes.in


android:label="@string/app_name"

android:theme="@style/AppTheme" >

<receiver android:name="MyReceiver">

<intent-filter>

<action android:name="android.intent.action.BOOT_COMPLETED">

</action>

</intent-filter>

</receiver>

</application>

8a. Intents and Intent Filters

An Intent is a messaging object you can use to request an action from another app component.
Although intents facilitate communication between components in several ways, there are three
fundamental use cases:

S . I N
OTE
Starting an activity

T U N
An Activity represents a single screen in an app. You can start a new instance of an Activity by

K
passing an Intent to startActivity(). The Intent describes the activity to start and carries any necessary
data.

If you want to receive a result from the activity when it finishes, call startActivityForResult(). Your
activity receives the result as a separate Intent object in your activity's onActivityResult() callback.
For more information, see the Activities guide.

Starting a service

A Service is a component that performs operations in the background without a user interface. With
Android 5.0 (API level 21) and later, you can start a service with JobScheduler. For more information
about JobScheduler, see its API-reference documentation.

For versions earlier than Android 5.0 (API level 21), you can start a service by using methods of the
Service class. You can start a service to perform a one-time operation (such as downloading a file) by
passing an Intent to startService(). The Intent describes the service to start and carries any necessary
data. If the service is designed with a client-server interface, you can bind to the service from another
component by passing an Intent to bindService(). For more information, see the Services guide.

Delivering a broadcast

Downloaded from Ktunotes.in


A broadcast is a message that any app can receive. The system delivers various broadcasts for system
events, such as when the system boots up or the device starts charging. You can deliver a broadcast to
other apps by passing an Intent to sendBroadcast() or sendOrderedBroadcast().

Intent types

There are two types of intents: Explicit intents specify which application will satisfy the intent, by
supplying either the target app's package name or a fully-qualified component class name. You'll
typically use an explicit intent to start a component in your own app, because you know the class
name of the activity or service you want to start. For example, you might start a new activity within
your app in response to a user action, or start a service to download a file in the background.

Implicit intents do not name a specific component, but instead declare a general action to perform,
which allows a component from another app to handle it. For example, if you want to show the user a
location on a map, you can use an implicit intent to request that another capable app show a specified
location on a map.

An intent filter is an expression in an app's manifest file that specifies the type of intents that the
component would like to receive. For instance, by declaring an intent filter for an activity, you make it
possible for other apps to directly start your activity with a certain kind of intent. Likewise, if you do
not declare any intent filters for an activity, then it can be started only with an explicit intent.

Building an intent

I N
An Intent object carries information that the Android system uses to determine which component to

S .
OTE
start (such as the exact component name or component category that should receive the intent), plus
information that the recipient component uses in order to properly perform the action (such as the

T U N
action to take and the data to act upon).

K
The primary information contained in an Intent is the following:

Component name

The name of the component to start.

This is optional, but it's the critical piece of information that makes an intent explicit, meaning that the
intent should be delivered only to the app component defined by the component name. Without a
component name, the intent is implicit and the system decides which component should receive the
intent based on the other intent information (such as the action, data, and category—described below).
If you need to start a specific component in your app, you should specify the component name.

Note: When starting a Service, always specify the component name. Otherwise, you cannot be certain
what service will respond to the intent, and the user cannot see which service starts.

Downloaded from Ktunotes.in


This field of the Intent is a ComponentName object, which you can specify using a fully qualified
class name of the target component, including the package name of the app, for example,
com.example.ExampleActivity. You can set the component name with setComponent(), setClass(),
setClassName(), or with the Intent constructor.

Action

A string that specifies the generic action to perform (such as view or pick).

In the case of a broadcast intent, this is the action that took place and is being reported. The action
largely determines how the rest of the intent is structured—particularly the information that is
contained in the data and extras.

You can specify your own actions for use by intents within your app (or for use by other apps to
invoke components in your app), but you usually specify action constants defined by the Intent class
or other framework classes. Here are some common actions for starting an activity:

ACTION_VIEW

Use this action in an intent with startActivity() when you have some information that an activity can
show to the user, such as a photo to view in a gallery app, or an address to view in a map app.

ACTION_SEND

Also known as the share intent, you should use this in an intent with startActivity() when you have
some data that the user can share through another app, such as an email app or social sharing app.

Data

The URI (a Uri object) that references the data to be acted on and/or the MIME type of that data. The
type of data supplied is generally dictated by the intent's action. For example, if the action is
ACTION_EDIT, the data should contain the URI of the document to edit.

When creating an intent, it's often important to specify the type of data (its MIME type) in addition to
its URI. For example, an activity that's able to display images probably won't be able to play an audio
file, even though the URI formats could be similar. Specifying the MIME type of your data helps the
Android system find the best component to receive your intent. However, the MIME type can
sometimes be inferred from the URI—particularly when the data is a content: URI. A content: URI
indicates the data is located on the device and controlled by a ContentProvider, which makes the data
MIME type visible to the system.

To set only the data URI, call setData(). To set only the MIME type, call setType(). If necessary, you
can set both explicitly with setDataAndType().

Caution: If you want to set both the URI and MIME type, don't call setData() and setType() because
they each nullify the value of the other. Always use setDataAndType() to set both URI and MIME
type.
Category- A string containing additional information about the kind of component that should handle
the intent. Any number of category descriptions can be placed in an intent, but most intents do not
require a category. Here are some common categories:

CATEGORY_BROWSABLE

The target activity allows itself to be started by a web browser to display data referenced by a link,
such as an image or an e-mail message.

CATEGORY_LAUNCHER

The activity is the initial activity of a task and is listed in the system's application launcher.

See the Intent class description for the full list of categories.

You can specify a category with addCategory().

These properties listed above (component name, action, data, and category) represent the defining
characteristics of an intent. By reading these properties, the Android system is able to resolve which
app component it should start. However, an intent can carry additional information that does not affect
how it is resolved to an app component. An intent can also supply the following information:

Extras - Key-value pairs that carry additional information required to accomplish the requested action.
Just as some actions use particular kinds of data URIs, some actions also use particular extras.

You can add extra data with various putExtra() methods, each accepting two parameters: the key
name and the value. You can also create a Bundle object with all the extra data, then insert the Bundle
in the Intent with putExtras().

8b. Android Manifesto

Every application must have an AndroidManifest.xml file (with precisely that name) in its root
directory. The manifest file provides essential information about your app to
theAndroid system, which the system must have before it can run any of the app's code. ...
It names the Java package for the application.

If you want to change the name of your app, then the manifest file isn't the place to look
for. Your app name can be changed from strings.xml file in the res/values/ folder. You can
do any formatting from within Eclipse itself during the development of your project/app

The Android System searches all apps for an intent filter that matches the intent. ...
An intent filter is an expression in an app's manifest file that specifies the type
ofintents that the component would like to receive.

An activity represents a single screen with a user interface just like window or frame of
Java.Android activity is the subclass of ContextThemeWrapper class.

9a. Drawable Resources

A drawable resource is a general concept for a graphic that can be drawn to the screen and
which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource
with attributes such as android:drawable and android:icon. There are several different types
of drawables: Bitmap File
A bitmap graphic file (.png, .jpg, or .gif). Creates a BitmapDrawable.

Nine-Patch File

A PNG file with stretchable regions to allow image resizing based on content (.9.png).
Creates a NinePatchDrawable.

Layer List

A Drawable that manages an array of other Drawables. These are drawn in array order, so
the element with the largest index is be drawn on top. Creates a LayerDrawable.

State List

An XML file that references different bitmap graphics for different states (for example, to use
a different image when a button is pressed). Creates a StateListDrawable.

Level List

An XML file that defines a drawable that manages a number of alternate Drawables, each
assigned a maximum numerical value. Creates a LevelListDrawable.

Transition Drawable

An XML file that defines a drawable that can cross-fade between two drawable resources.
Creates a TransitionDrawable.

Inset Drawable

An XML file that defines a drawable that insets another drawable by a specified distance.
This is useful when a View needs a background drawble that is smaller than the View's
actual bounds.

Clip Drawable

An XML file that defines a drawable that clips another Drawable based on this Drawable's
current level value. Creates a ClipDrawable.

Scale Drawable

An XML file that defines a drawable that changes the size of another Drawable based on its
current level value. Creates a ScaleDrawable

Shape Drawable

An XML file that defines a geometric shape, including colors and gradients. Creates a
ShapeDrawable.

9b. A style resource defines the format and look for a UI. A style can be applied to an individual View
(from within a layout file) or to an entire Activity or application (from within the manifest file).

Defining Styles
A style is defined in an XML resource that is separate from the XML that specifies the
layout. This XML file resides under res/values/ directory of your project and will
have <resources> as the root node which is mandatory for the style file. The name of the
XML file is arbitrary, but it must use the .xml extension.

You can define multiple styles per file using <style> tag but each style will have its name
that uniquely identifies the style. Android style attributes are set using <item> tag as shown
below −

<?xml version="1.0" encoding="utf-8"?>

<resources>

<style name="CustomFontStyle">

<item name="android:layout_width">fill_parent</item>

<item name="android:layout_height">wrap_content</item>

<item name="android:capitalize">characters</item>

<item name="android:typeface">monospace</item>

<item name="android:textSize">12pt</item>

<item name="android:textColor">#00FF00</item>/>

</style>

</resources>

The value for the <item> can be a keyword string, a hex color, a reference to another resource type, or
other value depending on the style property.

You might also like