0% found this document useful (0 votes)
8 views20 pages

Mad Ia-2

The document explains the differences between web apps and mobile apps, highlighting that web apps run in browsers and require internet, while mobile apps are installed on devices and can function offline. It also covers key Android concepts such as the Dalvik Virtual Machine, Activities, Picker Views, Menus, and various mobile technologies, as well as Android application components like Activities, Services, Broadcast Receivers, Content Providers, and Intent. Additionally, it discusses View Groups, data persistence methods in Android, and how to implement features like Action Bars and Image Views.
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)
8 views20 pages

Mad Ia-2

The document explains the differences between web apps and mobile apps, highlighting that web apps run in browsers and require internet, while mobile apps are installed on devices and can function offline. It also covers key Android concepts such as the Dalvik Virtual Machine, Activities, Picker Views, Menus, and various mobile technologies, as well as Android application components like Activities, Services, Broadcast Receivers, Content Providers, and Intent. Additionally, it discusses View Groups, data persistence methods in Android, and how to implement features like Action Bars and Image Views.
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/ 20

MAD IA-2

> Difference between web app and mobile app

A web app is a type of app that you open using a browser like Chrome
or Safari. You don’t need to install it. You just type the website
link (URL), and it opens. It always needs internet to work. It can
run on any device like phones, tablets, or computers — as long as you
have a browser.

A mobile app is an app that you download and install from the Play
Store or App Store. It works directly on your phone or tablet. Many
mobile apps can also work without internet, and they can use phone
features like the camera, GPS, or contacts more easily.

> What is Dalvik Virtual Machine?

The Dalvik Virtual Machine (DVM) was used in old Android phones. It
helps Android devices run apps.

When an Android app is made, the code is first written in Java, then
changed into a special format called DEX (Dalvik Executable). The DVM
runs this DEX code on the phone.

You can think of DVM as a translator that helps the phone understand
and run the app.

Now, newer Android versions use a faster system called ART (Android
Runtime) instead of DVM.

> What is an Activity in Android Studio?

An Activity is just one screen in an Android app.

For example:

●​ The login screen is one activity.​

●​ The home screen is another activity.​

Each activity shows a different part of the app. It has:

●​ A layout (what the user sees)​


●​ Code (what the app does when you click or type)​

An Android app usually has many activities connected together.

> What is a Picker View? List its types.

A Picker View lets the user choose something from a list, like a
date, time, or number.

Types of Picker Views:

●​ Date Picker – lets you select a date (day, month, year)​

●​ Time Picker – lets you select time (hours and minutes)​

●​ Number Picker – lets you choose a number from a list​

These are used to make choosing values faster and easier.

> What is a Menu? List its types.

A menu is a list of choices or actions in an app — like settings,


edit, or delete.

Types of menus in Android:

●​ Options Menu – appears when you press the 3 dots (⋮). It shows
general app options like settings.​

●​ Context Menu – appears when you long press on something. It


shows options just for that item (like delete or edit).​

●​ Popup Menu – shows a small menu next to a button when you click
it. For example, it might say "share", "copy", or "open".​

Menus help users use the app more easily.

> Explain different types of mobile technologies

Mobile technologies are the tools and systems that phones use to
work, connect, and communicate.

Here are some common types:

1
●​ 3G / 4G / 5G – These are mobile internet connections. 5G is the
fastest.​

●​ Bluetooth – Used for short-distance connections like wireless


headphones or sending files.​

●​ Wi-Fi – Used to connect to the internet through a router (at


home, schools, cafes, etc.).​

●​ GPS – Used for location. It helps in maps and travel apps.​

●​ NFC – Very short-distance technology. Used for things like


Google Pay or sending files by tapping two phones together.

> Briefly explain the key mobile application services

Mobile application services are the important building blocks of


Android apps. They help the app do its work properly, even when the
user is not touching the screen. These services allow different parts
of the app to talk to each other, do background tasks, and share data.

Here are the main services used in Android:

1. Activity​
An Activity is just one screen of the app that the user can see and
use.​
For example:

●​ A login screen is one activity.​

●​ A settings page is another activity.​


Each activity shows something different and allows the user to
do actions like typing or clicking buttons. So, an activity
controls what the screen looks like and what it does when the
user interacts with it.

2. Service​
A Service works in the background, which means it does its job even
when it’s not visible on the screen.​
For example:

●​ Playing music while you open another app​

●​ Downloading or uploading files in the background​

2
The service keeps running quietly, even when you’re doing something
else on your phone.

3. Broadcast Receiver​
A Broadcast Receiver listens for messages or signals from the
Android system or other apps.​
For example:

●​ When the phone battery is low​

●​ When the phone is charging​

●​ When a new SMS is received​

The broadcast receiver helps the app know about these events and take
some action when they happen.

4. Content Provider​
A Content Provider helps share data between apps safely.​
For example:

●​ One app can read your contacts or photos from another app (but
only if permission is given).​

It is used when an app wants to use or manage data that belongs to


another app in a secure and organized way.

5. Intent​
An Intent is like a message used to connect different parts of the
app — or even connect to other apps.​
For example:

●​ When you click a button to open a new screen, intent is used to


open that activity.​

●​ You can also use intent to start a background service or share


something like a photo.

> Write a note on:

a) Option Menu:​
The Option Menu is the main menu that you usually see in Android
apps. It shows up when you tap the three dots (⋮) in the top-right
corner of the screen.

3
This menu gives the user general options for the whole screen or
activity.​
For example:

●​ Settings​

●​ Search​

●​ Help​

●​ Logout

These options are not linked to one specific item — they work for the
entire screen.

How it works:

●​ The menu is created using a method called onCreateOptionsMenu().​

●​ The items (like "Settings" or "Logout") are written in an XML


file.​

●​ When the user taps on a menu item, the app handles it using
onOptionsItemSelected().

b) Context Menu:​
A Context Menu appears when the user long-presses (press and hold)
on something specific on the screen — like a message, an image, or a
list item.

It gives options that are related to just that item, not the whole
screen.​
For example, if you long-press on a message, you might see:

●​ Reply​

●​ Delete​

●​ Forward

These actions are only for that one message.

How it works:

4
●​ The menu is created using the onCreateContextMenu() method.​

●​ When the user picks an option, it is handled using


onContextItemSelected().

> Explain an Action Bar. How can you add action items to the
Action Bar?

Action Bar:​
The Action Bar is a bar at the top of the screen in Android apps. It
shows the name of the app and gives space for important buttons like
Search, Settings, or Help. It also helps users move between screens
or go back. This bar stays the same on every screen, so users always
know where to find key options.

The Action Bar mainly shows:

●​ The app's name and icon.​

●​ Navigation options (like back button or tabs).​

●​ Action items (important buttons like refresh, logout, etc.).

How to add action items to the Action Bar:

1.​First, create a new XML file (like menu_main.xml) in the


res/menu folder.​

2.​Inside the XML file, add action items using <item> tags. You can
give each item a title, icon, and set how it will appear using
android:showAsAction.​

Example:

xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_search"
android:title="Search"
android:icon="@drawable/ic_search"
android:showAsAction="ifRoom"/>

5
</menu>

3.​In your Java file (like MainActivity.java), override the


onCreateOptionsMenu() method to link the XML menu to your Action
Bar:​

java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

> Explain "image view" with an example.

ImageView:​
ImageView is a part of Android used to display images in an app. It
can show pictures from your app's files, from the internet, or from
your phone’s storage.

It is like a photo frame in your app that holds and shows a picture.

Example:​
Let’s say you want to show a logo in your app. You can use ImageView
to display that logo on the screen.

XML Example:

xml

<ImageView
android:id="@+id/myImage"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/logo" />

●​ android:id gives a name to the ImageView.​

6
●​ android:layout_width and android:layout_height set the size.​

●​ android:src is used to set the image you want to show (like


logo.png inside the drawable folder).

> Explain different android application components.

1. Activity:​
An Activity represents a screen in an app. Every time you open a new
page, it's an activity (like the home screen, login screen, etc.).

Example:​
A login screen where users enter their username and password is an
activity.

java
CopyEdit
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
}

2. Service:​
A Service is a component that runs in the background and performs
tasks without showing any UI. For example, playing music or
downloading a file.

Example:​
A music app that plays music in the background while you use other
apps.

java
CopyEdit
public class MusicService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Play music here
return START_STICKY;
}
}

7
3. Broadcast Receiver:​
A Broadcast Receiver listens for system-wide or app-specific events
(like battery status, SMS received, etc.) and reacts to them.

Example:​
A receiver that listens for when the battery is low and shows a
warning.

java
CopyEdit
public class BatteryReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BATTERY_LOW)) {
// Show low battery warning
}
}
}

4. Content Provider:​
A Content Provider allows data sharing between different apps. It
helps one app access data from another app securely, like accessing
contacts or photos.

Example:​
An app accessing another app’s contact list.

java
CopyEdit
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);

> Define "view group". Explain different types of view


groups supported by android.

View Group:​
A ViewGroup is a special type of View that can hold other views
(like buttons, images, etc.) inside it. It acts as a container for
child views and determines how they are arranged on the screen.

8
You can think of a ViewGroup as a parent for other views. It helps
organize and manage the layout of these views.

Types of View Groups in Android:

●​ LinearLayout:​
It arranges child views in either a vertical or horizontal
direction.​

Example:​
If you want buttons to be stacked vertically or arranged
side-by-side horizontally.​

xml​

<LinearLayout

android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Add buttons here →
</LinearLayout>
●​ RelativeLayout:​
It allows you to position child views relative to each other
or the parent container. Views can be placed on top, below,
left, right, etc.​

Example:​
Placing one button below another or aligning text on the right
side of a button.​

xml​

<RelativeLayout
​ android:layout_width="match_parent"
​ android:layout_height="match_parent">
​ <!-- Views with relative positions →
</RelativeLayout>
●​ ConstraintLayout:​
It helps you create complex layouts by defining constraints
between views. It’s more flexible and efficient for designing
complex UI structures.​

9
Example:​
You can specify constraints like "this button should be placed
below the text."​

xml​
CopyEdit​
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Views with constraints →
</androidx.constraintlayout.widget.ConstraintLayout>
●​ FrameLayout:​
It is used to stack views on top of each other. The child
views are placed in one corner, and the last one added appears
on top.​

Example:​
Showing an image with text over it.​

xml​
CopyEdit​
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Views stacked on top →
</FrameLayout>
●​ GridLayout:​
It arranges child views in a grid (rows and columns). You can
specify how many rows and columns you want.​

Example:​
Creating a simple calculator UI with buttons in rows and
columns.​

xml

<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rowCount="4"
android:columnCount="4">
<!-- Views arranged in grid →

10
</GridLayout>
> Write and explain the different ways in which data can be
saved in Android applications. (Hint : Data persistence and
its different ways)

1. SharedPreferences:

SharedPreferences is used to store small amounts of key-value data.


It’s ideal for saving simple app settings or preferences.

Example:​
You can save user login details or settings like theme preferences.

How it works:

●​ Data is stored in XML format in a file.​

●​ Suitable for small data (e.g., user preferences, app settings).​

java

SharedPreferences preferences = getSharedPreferences("MyPrefs",


MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("username", "JohnDoe");
editor.putInt("userAge", 25);
editor.apply();

2. Internal Storage:

Internal storage allows you to store data privately on the device’s


internal memory. Only the app can access this data, and it persists
even after the app is closed.

Example:​
Storing files like images, documents, or text files.

How it works:

●​ Files are stored in the app’s private directory.​

11
●​ Other apps cannot access this data.​

java

FileOutputStream fos = openFileOutput("myfile.txt", MODE_PRIVATE);


fos.write("Hello, World!".getBytes());
fos.close();

3. External Storage:

External storage is used to store data that can be shared with other
apps. This can be on the device's external SD card or other external
media.

Example:​
Saving large files like videos, photos, or music.

How it works:

●​ Files are stored on the external storage (SD card).​

●​ It can be accessed by other apps (with user permission).​

●​ Requires storage permissions (READ_EXTERNAL_STORAGE,


WRITE_EXTERNAL_STORAGE).​

java

File file = new File(Environment.getExternalStorageDirectory(),


"myfile.txt");
FileOutputStream fos = new FileOutputStream(file);
fos.write("Hello from external storage!".getBytes());
fos.close();

4. SQLite Database:

SQLite is a lightweight database engine used in Android for storing


structured data. It is used for more complex data storage needs, like
saving user data in tables with rows and columns.

12
Example:​
Saving user data, like contacts, in a structured way.

How it works:

●​ Android provides a built-in SQLite database engine.​

●​ You can create tables, insert, update, and query data.​

java

SQLiteDatabase db = openOrCreateDatabase("MyDatabase", MODE_PRIVATE,


null);
db.execSQL("CREATE TABLE IF NOT EXISTS Users (id INTEGER PRIMARY KEY,
name TEXT)");
db.execSQL("INSERT INTO Users (name) VALUES ('John Doe')");

5. Content Providers:

Content Providers are used for sharing data between different


applications. It allows one app to access data stored by another app,
like contacts, media, or calendar data.

Example:​
Accessing contact information or sharing app data with other apps.

How it works:

●​ A content provider manages a specific set of data (like


contacts or media).​

●​ The app accesses this data using a URI (Uniform Resource


Identifier).​

java

Cursor cursor = getContentResolver().query(


ContactsContract.Contacts.CONTENT_URI,
null,
null,
null,

13
null
);

6. Room Database:

Room is an abstraction layer over SQLite, which makes it easier to


work with databases in Android. It uses annotations and provides an
object-oriented interface for working with databases.

Example:​
Saving user-related data with complex relationships, like user
profiles, tasks, etc.

How it works:

●​ Room provides an easy-to-use API for storing structured data.​

●​ It is preferred for apps that require local database storage


but want to avoid writing raw SQL queries.​

java

@Entity
public class User {
@PrimaryKey
public int id;
public String name;
}

@Dao
public interface UserDao {
@Insert
void insert(User user);
}

Room.databaseBuilder(context, AppDatabase.class,
"database-name").build();

14
> Explain different types of "Basic views".

In Android, basic views are the fundamental building blocks for


creating user interfaces. They represent visual components that can
be displayed on the screen and interacted with. Here are the
different types of basic views:

1. TextView

●​ Purpose: Displays text on the screen.​

●​ Example Usage: Showing labels, titles, or any other text-based


information.​

Code Example:​

xml​

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />

2. Button

●​ Purpose: A clickable button that performs an action when


pressed.​

●​ Example Usage: Used for actions like submitting a form,


navigating, or performing any task.​

Code Example:​

xml​

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />

15
3. ImageView

●​ Purpose: Displays images on the screen.​

●​ Example Usage: Used to show pictures, icons, or graphics.​

Code Example:​

xml​

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sample_image" />

4. EditText

●​ Purpose: A field for user input, usually for text.​

●​ Example Usage: For capturing text input like name, email, or any
form field.​

Code Example:​

xml​

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name" />

5. CheckBox

●​ Purpose: A checkbox that allows users to select or deselect an


option.​

●​ Example Usage: Used in forms where multiple selections are


allowed (e.g., agreeing to terms).​

16
Code Example:​

xml​

<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I agree" />

6. RadioButton

●​ Purpose: A button that allows the user to select one option from
a group.​

●​ Example Usage: Used in scenarios where only one option from a


set can be selected (e.g., gender selection).​

Code Example:​

xml​

<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />

7. Switch

●​ Purpose: A switch widget for toggling between two states


(on/off).​

●​ Example Usage: Used for settings where the user can enable or
disable features.​

Code Example:​

xml​

<Switch

17
android:id="@+id/switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable Notifications" />

8. ProgressBar

●​ Purpose: A visual indicator of progress, such as loading or


waiting.​

●​ Example Usage: To show the status of a task (e.g., file download


or upload).​

Code Example:​

xml​

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />

9. ImageButton

●​ Purpose: A button that displays an image instead of text.​

●​ Example Usage: Used when you want to make a button look like an
icon.​

Code Example:​

xml​

<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:contentDescription="Click me" />

18
10. Spinner

●​ Purpose: A dropdown list to select a single item from a set of


options.​

●​ Example Usage: For selecting an option, like a country or a


category.​

Code Example:​

xml​

<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"

android:layout_height="wrap_content" />

19

You might also like