100% found this document useful (1 vote)
571 views21 pages

Android App Development Guide

The document contains 16 questions related to developing Android applications using various layouts like table, absolute, relative and linear layouts. It also includes questions on important Android concepts like activities, intents, fragments, services, content providers, SQLite, geocoding and reverse geocoding. The questions require developing simple Android apps to demonstrate different layouts and concepts or explaining the concepts and providing code snippets.

Uploaded by

sofiyan
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
100% found this document useful (1 vote)
571 views21 pages

Android App Development Guide

The document contains 16 questions related to developing Android applications using various layouts like table, absolute, relative and linear layouts. It also includes questions on important Android concepts like activities, intents, fragments, services, content providers, SQLite, geocoding and reverse geocoding. The questions require developing simple Android apps to demonstrate different layouts and concepts or explaining the concepts and providing code snippets.

Uploaded by

sofiyan
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

4marks Questions

1. Develop an android application using table layout.

2. Explain following files

Main Activity File 2. Manifest File 3. String File 4. Layout file

3. Develop an android application using absolute layout.

4. Describe android and important of OHA.

5. Explain intent and fragments.

6. Develop an android application using relative layout.

7. Enlist the use of following UI components.

1. Text View 2. Button 3. Image Button 4. Toggle Button 5.Radio Button 6. Radio Group
Button. 7. Custom Toast alert 8.Scroll View

8. Explain life cycle of service in android.

9. Develop an android application using frame layout.

10. Explain the use of List View and grid view.

11. Explain SQLite database and create database of your choice.

12. Explain the concept of geocoding and reverse geocoding.

13. Describe Location based services.

14. What is the fragment? How fragments can be created and explain any one methods
with appropriate code to create fragment ?

15. Develop an android application using linear layout.

16. Describe Android eco system.

1
4 Marks Question Answers

1. Develop an android application using table layout.


Ans: MainActivity.java File:
package com.example.demo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml File
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textClock"
android:layout_column="2" />
</TableRow>
<TableRow>
<TextView
android:text="First Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<EditText
android:width="200px"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>

2
<TableRow>
<TextView
android:text="Last Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<EditText
android:width="100px"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:layout_column="2" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/button"
android:layout_column="2" />
</TableRow>
</TableLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloWorld</string>
<string name="action_settings">Settings</string>
</resources>

3
2. Explain following files:
1. Main Activity File 2. Manifest File 3. String File 4. layout file?
Ans: 1. The Main Activity File: The main activity code is a Java file MainActivity.java. This
is the actual application file which ultimately gets converted to a Dalvik executable and runs
your application. Following is the default code generated by the application wizard for Hello
World! application:
package com.example.helloworld;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Here, R.layout.activity_main refers to the activity_main.xml file located in the res/layout folder.
The onCreate() method is one of many methods that are figured when an activity is loaded.
2. The Manifest File: Whatever component you develop as a part of your application, you must
declare all its components in a manifest.xml which resides at the root of the application project
directory. This file works as an interface between Android OS and your application, so if you do
not declare your component in this file, then it will not be considered by the OS. For example, a
default manifest file will look like as following file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ProgramDemo.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

4
Following is the list of tags which you will use in your manifest file to specify different
Android application components:
<activity>elements for activities
<service> elements for services
<receiver> elements for broadcast receivers
<provider> elements for content providers
3. The Strings File: The strings.xml file is located in the res/values folder and it contains all the
text that your application uses. For example, the names of buttons, labels, default text, and
similar types of strings go into this file. This file is responsible for their textual content. For
example, a default strings file will look like as following file:
<resources>
<string name="app_name">HelloWorld</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
4. The Layout File: The activity_main.xml is a layout file available in res/layout directory, that
is referenced by your application when building its interface. You will modify this file very
frequently to change the layout of your application. For your "Hello World!" application, this file
will have following content related to default layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
This is an example of simple RelativeLayout. The TextView is an Android control used to build
the GUI and it have various attributes like android:layout_width, android:layout_height etc
which are being used to set its width and height etc.. The @string refers to the strings.xml file
located in the res/values folder. Hence, @string/hello_world refers to the hello string defined in
the strings.xml file, which is "Hello World!"

5
3. Develop an android application using absolute layout.
Ans: Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity">
<!--Setting up TextViews-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="100px"
android:layout_y="300px" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="120px"
android:layout_y="350px" />
</AbsoluteLayout>
colors.xml
<resources>
<color name="colorPrimary">#0F9D58</color>
<color name="colorPrimaryDark">#16E37F</color>
<color name="colorAccent">#03DAC5</color>
</resources>
mainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView heading, subHeading;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Referencing the TextViews

6
heading = (TextView) findViewById(R.id.heading);
subHeading = (TextView) findViewById(R.id.subHeading);
// Setting text dynamically
heading.setText("Computer Science Portal");
subHeading.setText("GeeksForGeeks");
}
}

4. Describe android and important of OHA.


Ans: Android is a software package and Linux based operating system for mobile devices such
as tablet computers and smartphones. It is developed by Google and later the OHA (Open
Handset Alliance). Java language is mainly used to write the android code even though other
languages can be used. The goal of android project is to create a successful real-world product
that improves the mobile experience for end users. There are many code names of android such
as Lollipop, Kitkat, Jelly Bean, Ice cream Sandwich, Froyo, Ecliar, Donut etc which is covered
in next page.
The Open Handset Alliance (OHA): is a business alliance that was created for the purpose of
developing open mobile device standards. The OHA is a group of more than 80 companies,
including Google, HTC, Dell, Intel, Motorola, Qualcomm. OHA's main product is the Android
platform - the world's most popular smartphone platform. Android is open to everyone:
developers, designers, and device makers. That means more people can experiment, imagine, and
create the world has never seen. The Open Handset Alliance is an association of 84 companies
developing free standards for mobile devices. Member companies include HTC, Sony, Dell,
Intel, Motorola, etc.

5. Explain intent and fragments.


Ans:Intent is to perform an action. It is mostly used to start activity, send broadcast receiver,
start services and send message between two activities. There are two intents available in android
as Implicit Intents and Explicit Intents.
Explicit Intent: It going to connect the internal world of an application such as start activity or
send data between two activities. To start new activity we have to create Intent object and pass
source activity and destination activity as shown below:
Intent send = new Intent(MainActivity.this, SecondActivity.class);
startActivity(send);
Implicit Intents: It going to connect with out side application such as call, mail, phone,see any
website etc. In implicit intent we have to pass an action using setAction() as shown below:
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("www.yourwebsite.com"));
startActivity(i);

7
Android Fragment: it is the part of activity, it is also known as sub-activity. There can be more
than one fragment in an activity. Fragments represent multiple screen inside one activity.
Android fragment lifecycle is affected by activity lifecycle because fragments are included in
activity. Each fragment has its own life cycle methods that is affected by activity life cycle
because fragments are embedded in activity. The FragmentManager class is responsible to make
interaction between fragment objects.
Basically fragments are divided as three stages as shown below.
Single frame fragments: Single frame fragments are using for hand hold devices like mobiles,
here we can show only one fragment as a view.
List fragments: fragments having special list view is called as list fragment
Fragments transaction: Using with fragment transaction. we can move one fragment to another
fragment.

6. Develop an android application using relative layout.


Ans: MainActivity.java File:
package com.example.demo;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml File:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/reminder" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

8
android:layout_alignParentStart="true"
android:layout_below="@+id/name">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2" />
</LinearLayout>
</RelativeLayout>
strings.xml File:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="action_settings">Settings</string>
<string name="reminder">Enter your name</string>
</resources>

7. Enlist the use of following UI components.


1. Text View 2. Button 3. Image Button 4. Toggle Button 5. Radio Button 6. Radio
Group Button. 7. Custom Toast alert 8. Scroll View
Ans:
1. Text View: A TextView displays text to the user and optionally allows them to edit it. A
TextView is a complete text editor, however the basic class is configured to not allow editing.
2. Button: A Button is a Push-button which can be pressed, or clicked, by the user to perform an
action.
3. Image Button: An ImageButton is an AbsoluteLayout which enables you to specify the exact
location of its children. This shows a button with an image (instead of text) that can be pressed or
clicked by the user.
4. Toggle Button: A ToggleButton displays checked/unchecked states as a button. It is basically
an on/off button with a light indicator.
5. Radio Button: A RadioButton has two states: either checked or unchecked.This allows the
user to select one option from a set.
6. Radio Group Button: A RadioGroup class is used for set of radio buttons. If we check one
radio button that belongs to a radio group, it automatically unchecks any previously checked
radio button within the same group.

9
7. Custom Toast alert: Toast is a small popup notification that is used to display information
about the operation which we performed in our app. The Toast will show the message for a small
period of time and it will disappear automatically after a timeout.
8. Scroll View: ScrollView is a view group that is used to make vertically scrollable views. A
scroll view contains a single direct child only. In order to place multiple views in the scroll view,
one needs to make a view group (like LinearLayout) as a direct child and then we can define
many views inside it.

8. Explain life cycle of service in android.


Ans: There can be two forms of a service. The lifecycle of service can follow two different
paths: started or bound.
1) Started Service: A service is started when component (like activity) calls startService()
method, now it runs in the background indefinitely. It is stopped by stopService() method. The
service can stop itself by calling the stopSelf() method.
2) Bound Service: A service is bound when another component (e.g. client) calls bindService()
method. The client can unbind the service by calling the unbindService() method.
The service cannot be stopped until all clients unbind the service.

10
9. Develop an android application using frame layout.
Ans: MainActivity.java File:
package com.example.demo;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml File:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:src="@drawable/ic_launcher"
android:scaleType="fitCenter"
android:layout_height="250px"
android:layout_width="250px"/>
<TextView
android:text="Frame Demo"
android:textSize="30px"
android:textStyle="bold"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center"/>
</FrameLayout>
strings.xml File:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">demo</string>
<string name="action_settings">Settings</string>
</resources>

11
10. Explain the use of List View and grid view.
Ans: A GridView is a type of AdapterView that displays items in a two-dimensional scrolling
grid. Items are inserted into this grid layout from a database or from an array. The adapter is used
for displaying this data, setAdapter() method is used to join the adapter with GridView. The
main function of the adapter in GridView is to fetch data from a database or array and insert each
piece of data in an appropriate item that will be displayed in GridView. This is how the
GridView structure looks like.
A ListView is a type of AdapterView that displays a vertical list of scroll-able views and each
view is placed one below the other. Using adapter, items are inserted into the list from an array
or database. For displaying the items in the list method setAdaptor() is used. setAdaptor()
method conjoins an adapter with the list. Android ListView is a ViewGroup that is used to
display the list of items in multiple rows and contains an adapter that automatically inserts the
items into the list. The main purpose of the adapter is to fetch data from an array or database and
insert each item that placed into the list for the desired result. So, it is the main source to pull
data from strings.xml file which contains all the required strings in Java or XML files.

11. Explain SQLite database and create database of your choice.


Ans: SQLite is a opensource SQL database that stores data to a text file on a device. Android
comes in with built in SQLite database implementation. SQLite supports all the relational
database features. In order to access this database, you don't need to establish any kind of
connections for it like JDBC,ODBC e.t.c
Database Creation:
In order to create a database you just need to call this method openOrCreateDatabase with your
database name and mode as a parameter. It returns an instance of SQLite database which you
have to receive in your own object. Its syntax is given below:
SQLiteDatabase mydatabase = openOrCreateDatabase("your database name",MODE_PRIVATE,null);

12
DatabaseDemoActivity.java
package com.DataBaseDemo;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class DataBaseDemoActivity extends Activity {
/** Called when the activity is first created. */
SQLiteDatabase db;
Button btnInsert;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnInsert=(Button)findViewById(R.id.button1);
try{

db=openOrCreateDatabase("StudentDB",SQLiteDatabase.CREATE_IF_NECESSARY,null);
db.execSQL("Create Table Temp(id integer,name text)");
}catch(SQLException e)
{
}
btnInsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText eid=(EditText) findViewById(R.id.editText1);
EditText ename=(EditText)findViewById(R.id.editText2);
ContentValues values=new ContentValues();
values.put("id", eid.getText().toString());
values.put("name", ename.getText().toString());

13
if((db.insert("temp", null, values))!=-1)
{
Toast.makeText(DataBaseDemoActivity.this, "Record Successfully Inserted", 2000).show();
}
else
{
Toast.makeText(DataBaseDemoActivity.this, "Insert Error", 2000).show();
}
eid.setText("");
ename.setText("");
Cursor c=db.rawQuery("SELECT * FROM temp",null);
c.moveToFirst();
while(!c.isAfterLast())
{
Toast.makeText(DataBaseDemoActivity.this,c.getString(0)+ ""+c.getString(1),1000).show();
c.moveToNext();
}
c.close();
}
});
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
db.close();
super.onStop();
}
}

14
12. Explain the concept of geocoding and reverse geocoding.
Ans: We can achieve this by using Geocoder class. Finding the geographical coordinates
(latitude and longitude) of a given address or location is called Geocoding. opposite of
geocoding where a pair of latitude and longitude is converted into an address or location called
as Reverse Geocode. Geocode or Reverse Geocode is achieved by importing the proper package.
import android.location.Geocoder;
The geocoding or reverse geocoding operation needs to be done on a separate thread and should
never be used on the UI thread as it will cause the system to display an Application Not
Responding (ANR) dialog to the user.
Example:
Geocoder ge= new Geocoder(context);
if(gc.isPresent()){
List<Address> list = gc.getFromLocationName("155 Park Theater, Palo Alto, CA", 1);
Address address = list.get(0);
double lat = address.getLatitude();
double Ing = address.getLongitude():
}
For reverse Geocode:
Geocoder gc = new Geocoder(context);
if(gc.isPresent()){
List<address> list = gc.getFromLocation(37.42279,122.08506,1);
Address address list.get(0);
StringBuffer str = new StringBuffer(); str.append("Name: " + address.getLocality() + "\n");
str.append("Sub-Admin Ares: " + address.getSubAdminArea() + "\n");
str.append("Admin Area: " + address.getAdminArea() + "\n");
str.append("Country: " + address.getCountryName() + "\n");
str.append("Country Code: " + address.getCountryCode() + "\n");
String strAddress = str.toString();
}

13. Describe Location based services.


Ans: Location-Based Services(LBS) are present in Android to provide you with features like
current location detection, display of nearby places, geofencing, etc. It fetches the location using
your device’s GPS, Wifi, or Cellular Networks. To build an app with location-based services,
you need to access the Google Play Services Module. After that, you need to use a framework
called Location Framework, which has many methods, classes, and interfaces to make your task
easier.

15
Components of Location-Based Services in Android:
The classes and the interfaces present in the Location Framework acts as the essential
components for LBS. Those components are as follows:
LocationManager Class: It is used to get Location Service access from the system.
LocationListener Interface: It receives updates from the Location Manager class.
LocationProvider: It is the class that provides us with the location for our devices.
Location Class: Its objects carry information about the location. The information includes
latitude, longitude, accuracy, altitude, and speed.
Location Object: The location objects carry the location of your device. The place is in the form
of latitude and longitude. On the location object, you can apply the below methods. The below
methods help you to get location and other information regarding the location.
1. float distanceTo(Location destination): It gives the approximate distance between our current
location and the destination location.
2. float getAccuracy(): It gives us the accuracy of our location in metres.
3. double getAltitude(): It gives us the altitude of our place above sea level.
4. double getLatitude(): It gives the latitude coordinate of our place in degrees.

14. What is the fragment? How fragments can be created and explain any one
methods with appropriate code to create fragment?
Ans: Android Fragment is the part of activity, it is also known as sub-activity. There can be
more than one fragment in an activity. Fragments represent multiple screen inside one activity.
Android fragment lifecycle is affected by activity lifecycle because fragments are included in
activity. Each fragment has its own life cycle methods that is affected by activity life cycle
because fragments are embedded in activity. The FragmentManager class is responsible to make
interaction between fragment objects.
Android Fragment Lifecycle Methods:
1) onAttach(Activity): it is called only once when it is attached with activity.
2) onCreate(Bundle): It is used to initialize the fragment.
3) onCreateView(LayoutInflater, ViewGroup, Bundle): creates and returns view hierarchy.
4) onActivityCreated(Bundle): It is invoked after the completion of onCreate() method.
5) onViewStateRestored(Bundle): It provides information to the fragment that all the saved
state of fragment view hierarchy has been restored.
6) onStart(): makes the fragment visible.
7) onResume(): makes the fragment interactive.
8) onPause(): is called when fragment is no longer interactive.
9) onStop(): is called when fragment is no longer visible.
10) onDestroyView(): allows the fragment to clean up resources.
11) onDestroy(): allows the fragment to do final clean up of fragment state.
12) onDetach(): It is called immediately prior to the fragment no longer being associated with its
activity.

16
Example:
activity_main.xml File:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="example.javatpoint.com.fragmentexample.MainActivity">
<fragment
android:id="@+id/fragment1"
android:name="example.javatpoint.com.fragmentexample.Fragment1"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<fragment
android:id="@+id/fragment2"
android:name="example.javatpoint.com.fragmentexample.Fragment2"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
fragment_fragment1.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F5F5DC"
tools:context="example.javatpoint.com.fragmentexample.Fragment1">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
fragment_fragment2.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

17
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0FFFF"
tools:context="example.javatpoint.com.fragmentexample.Fragment2">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
MainActivity.java
package example.javatpoint.com.fragmentexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Fragment1.java
package example.javatpoint.com.fragmentexample;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment1 extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fragment1, container, false);
}
}

18
Fragment2.java
package example.javatpoint.com.fragmentexample;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment2 extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fragment2, container, false);
}
}

15. Develop an android application using linear layout.


Ans: ActivityMain.java
package com.example.demo;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Activitymain.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

19
<Button android:id="@+id/btnStartService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="start_service"/>
<Button android:id="@+id/btnPauseService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="pause_service"/>
<Button android:id="@+id/btnStopService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="stop_service"/>
</LinearLayout>
Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloWorld</string>
<string name="action_settings">Settings</string>
</resources>

Output:

20
16. Describe Android ecosystem.
Ans: ecosystem is nothing but the relationship between Users, Developers/Programmers, and
Hardware equipment makers, the Android ecosystem is nothing but the mutual dependence
between Users, Developers, and equipment makers. they are independent of each other so one
cannot exist without the other.
The main three block of the android ecosystem is as follow:
1. Android User (Users buy handsets and software Application): Android users have more
space for customizability for their android devices. Android users are smarter than other users
and they are perceived to have greater levels of support. Android users are also more likely to
prefer saving their cost and love the openness of the platform also they like to customize their
device. Android users are fancier to prefer saving money and also android user like customizing
their android handset/device
2. Developers (sell Application): Android Developers are the professional software developer in
designing applications as well as developing applications for Android. Some of the following
tasks where an android developer can play his role in the development of android apps: Design
and build advanced applications for the android platform Collaborate and define with
development teams for design and deliver new cool features. Troubleshoot and fix bugs in new
and existing applications for Users. Evaluate and implement new development tools to work with
outside data sources and APIs.
3. Equipment Maker: Android equipment’s are available in the market in a huge amount.
Smartwatches: A smartwatch is a handheld, wearable device that closely relates a wristwatch or
other time device. In addition to telling time, many smartwatches are wireless connectivity
oriented such as Bluetooth capable. The traditional watch becomes, in effect, a wireless
Bluetooth technology extending the capabilities of the wearer's smartphone to the watch.
Smart TV: An Android TV box is a small computer that plugs into any TV and gives the user
the ability to stream content, locally and online. Apps can be downloaded from the Google Play
Store, installed, and do most anything a standard computer can do from streaming videos to
writing an email.
Smart Speakers: Smark speakers are booming in the market now, Smark speakers like Google
Home, Alexa, We can control our android device via voice using these smart speakers.
E-Reader: E-Reader is a device used for reading e-books, digital newspapers, other reading
stuff.

21

You might also like