• Eight Marks Questions:
13) Explain the layers of Android architecture.
Android architecture is divided into four main layers:
1. Linux Kernel:
Base of Android architecture.
Provides hardware abstraction, memory management, process management, power
management, and device drivers (camera, Bluetooth, display, etc.).
2. Libraries and Android Runtime:
Libraries: Written in C/C++, include Surface Manager, Media Framework, SQLite, WebKit,
SSL, etc.
Android Runtime (ART): Core of Android’s virtual machine, includes core libraries and the
Dalvik/ART for running applications.
3. Application Framework:
Provides high-level services in Java to applications.
Includes Activity Manager, Package Manager, Telephony Manager, Location Manager,
Window Manager, etc.
4. Applications:
The top layer where apps like Contacts, Email, Browser, and third-party apps run.
Built using the APIs provided by the framework.
14) Mention and explain each different method of DatePicker.
DatePicker in Android allows users to select a date. Key methods include:
1. getDayOfMonth() – Returns the selected day.
2. getMonth() – Returns the selected month.
3. getYear() – Returns the selected year.
4. init(int year, int month, int day, OnDateChangedListener listener) – Initializes the date and
registers a listener for date changes.
5. updateDate(int year, int month, int day) – Updates the current date shown.
6. setEnabled(boolean enabled) – Enables or disables the widget.
7. setCalendarViewShown(boolean shown) – Shows/hides the calendar view.
8. setSpinnersShown(boolean shown) – Shows/hides the spinner inputs.
These methods allow flexible control over date input in Android apps.
15) What is menu in Android Studio? Explain the steps of creating a menu.
A menu in Android is a UI component that provides options to users. Types: Options Menu, Context
Menu, and Popup Menu.
Steps to create a menu:
1. Create menu XML in res/menu/menu_example.xml:
2. <menu xmlns:android="http://schemas.android.com/apk/res/android">
3. <item android:id="@+id/item1" android:title="Item 1"/>
4. <item android:id="@+id/item2" android:title="Item 2"/>
5. </menu>
6. Inflate menu in Activity:
7. @Override
8. public boolean onCreateOptionsMenu(Menu menu) {
9. getMenuInflater().inflate(R.menu.menu_example, menu);
10. return true;
11. }
12. Handle menu item clicks:
13. @Override
14. public boolean onOptionsItemSelected(MenuItem item) {
15. switch (item.getItemId()) {
16. case R.id.item1:
17. // action
18. return true;
19. case R.id.item2:
20. // action
21. return true;
22. default:
23. return super.onOptionsItemSelected(item);
24. }
25. }
16) Define content provider. Discuss the working flow of content provider in Android.
A Content Provider manages access to a structured set of data. It encapsulates the data and
provides mechanisms for defining data security.
Working Flow:
1. Create a Content Provider by extending ContentProvider class.
2. Override core methods:
insert(), query(), update(), delete(), and getType().
3. Define authority and URIs in AndroidManifest.xml.
4. Access data using ContentResolver:
Example: Cursor cursor = getContentResolver().query(uri, ...);
5. Other apps can access this provider via URI if permission is granted.
It allows sharing data across different applications securely.
17) Discuss the methods of SQLiteOpenHelper class in Android Studio.
SQLiteOpenHelper helps in managing database creation and version management.
Key Methods:
1. onCreate(SQLiteDatabase db):
Called when the database is created.
Use it to create tables.
2. db.execSQL("CREATE TABLE students(id INTEGER PRIMARY KEY, name TEXT)");
3. onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion):
Called when database version is updated.
Drop old tables and create new ones.
4. getReadableDatabase() and getWritableDatabase():
Returns readable or writable database instance.
Example class:
public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "StudentDB", null, 1);
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE students(id INTEGER PRIMARY KEY, name TEXT)");
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS students");
onCreate(db);
18) Elaborate different types of layout in Android Studio.
Android provides several layout types to arrange UI components:
1. LinearLayout:
Arranges views vertically or horizontally.
Simple and flexible.
2. RelativeLayout:
Positions views relative to each other or the parent.
Useful for complex UI.
3. ConstraintLayout:
Most flexible and efficient.
Uses constraints to position views, supports chains and barriers.
4. FrameLayout:
Stacks views on top of each other.
Used for displaying a single view or overlapping views.
5. TableLayout:
Organizes views into rows and columns.
Like an HTML table.
6. GridLayout:
Displays items in a grid (rows and columns).
Similar to TableLayout but more flexible.
Each layout type serves specific use-cases and can be nested for more complex designs.