Test your Android Skills !!
1) What is Android?
Android is an open-source, linux-based operating system that is used in mobiles, tablets, televisions etc.
2) Who is the founder of Android?
Andy Rubin.
3) What are the code names of android?
Aestro
Blender
Cupcake
Donut
Eclair
Froyo
Gingerbread
Honycomb
Ice Cream Sandwitch
Jelly Bean
Kitkat
More details...
4) What are the advantages of android?
Open-source: It means no licence, distribution and development fee.
Platform-independent: It supports windows, mac and linux platforms.
Supports various technologies: It supports camera, bluetooth, wifi, speech, EDGE etc. technologies.
Highly optimized Virtual Machine: Android uses highly optimized virtual machine for mobile devices, called DVM (Dalvik Virtual Machine).
5) Does android support other language than java?
Yes, android app can be developed in C/C++ also using android NDK (Native Development Kit). It makes the performance faster. It should be used with android SDK.
6) What are the core building blocks of android?
The core building blocks of android are:
Activity
View
Intent
Service
Content Provider
Fragment etc.
More details...
7) What is activity?
Activity is like a frame or window in java that represents GUI. It represents one screen of android.
8) What are the life cycle methods of android activity?
There are 7 life-cycle methods of activity. They are as follows:
onCreate()
onStart()
onResume()
onPause()
onStop()
onRestart()
onDestroy()
More details...
9) What is intent?
It is a kind of message or information that is passed to the components. It is used to launch an activity, display a web page, send sms, send email etc. There are two types of intents in android:
Implicit Intent
Explicit Intent
10) What is implicit intent in android?
Implicit intent is used to invoke the system components.
11) What is explicit intent in android?
Explicit intent is used to invoke the activity class.
12) How to call another activity in android?
Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
startActivity(i);
13) What is service in android?
A service is a component that runs in the background. It is used to play music, handle network transaction etc.
More details...
14) What is the name of database used in android?
SQLite: An opensource and lightweight relational database for mobile devices.
More details...
15) What is AAPT?
AAPT is an acronym for android asset packaging tool. It handles the packaging process.
16) What is content provider?
Content providers are used to share information between android applications.
17) What is fragment?
Fragment is a part of Activity. By the help of fragments, we can display multiple screens on one activity.
18) What is ADB?
ADB stands for Android Debug Bridge. It is a command line tool that is used to communicate with the emulator instance.
19) What is NDK?
NDK stands for Native Development Kit. By using NDK, you can develop a part of app using native language such as C/C++ to boost the performance.
20) What is ANR?
ANR stands for Application Not Responding. It is a dialog box that appears if the application is no longer responding.
Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google. With a user interface based on direct manipulation, Android is designed primarily for touchscreen mobile devices such as smartphones and tablet computers, with specialized user interfaces for televisions (Android TV), cars (Android Auto), and wrist watches (Android Wear).
The OS uses touch inputs that loosely correspond to real-world actions, like swiping, tapping, pinching, and reverse pinching to manipulate on-screen objects, and a virtual keyboard.
Despite being primarily designed for touchscreen input, it also has been used in game consoles, digital cameras, regular PCs (e.g. the HP Slate 21) and other electronics.
1. What is meaning of Android Word?
it means a robot with a human appearance.
2. What is Android?
an open-source operating system used for smartphones and tablet computers.
3. Inventors of android ?
Andy Rubin, Rich Miner, Nick Sears
4. Android versions history and there name?
Code name
|
Version
|
API level
|
Lollipop
|
5.0
|
API level 21
|
KitKat
|
4.4 - 4.4.4
|
API level 19
|
Jelly Bean
|
4.3.x
|
API level 18
|
Jelly Bean
|
4.2.x
|
API level 17
|
Jelly Bean
|
4.1.x
|
API level 16
|
Ice Cream Sandwich
|
4.0.3 - 4.0.4
|
API level 15, NDK 8
|
Ice Cream Sandwich
|
4.0.1 - 4.0.2
|
API level 14, NDK 7
|
Honeycomb
|
3.2.x
|
API level 13
|
Honeycomb
|
3.1
|
API level 12, NDK 6
|
Honeycomb
|
3.0
|
API level 11
|
Gingerbread
|
2.3.3 - 2.3.7
|
API level 10
|
Gingerbread
|
2.3 - 2.3.2
|
API level 9, NDK 5
|
Froyo
|
2.2.x
|
API level 8, NDK 4
|
Eclair
|
2.1
|
API level 7, NDK 3
|
Eclair
|
2.0.1
|
API level 6
|
Eclair
|
2.0
|
API level 5
|
Donut
|
1.6
|
API level 4, NDK 2
|
Cupcake
|
1.5
|
API level 3, NDK 1
|
(no code name)
|
1.1
|
API level 2
|
(no code name)
|
1.0
|
API level 1
|
5. Features of Android OS?
Most of us are aware of features like
Live wallpaper
Camera
Messaging
Bluetooth
WIFI
Web Browsing
Music
Alarm etc. etc….
6. Advance Features of Android OS?
Google now (voice assistant)
NFC (Near Field Communication)
Unlock your phone by your face
Use your phone with joystick to enjoy gaming experience
Connect your phone with LED TV via MHL or micro HDMI cable
Screen Capture
Multitasking Future (Task Switcher)
Data Usages (Check and also set limit from device)
7. Tools Required for Developing Android Apps?
JDK
Eclipse + ADT plugin
SDK Tools.
8. ADT stand for?
Android Developer Tools
9. SDK stand for ?
Software Development Kit
10. Advantages of android?
Open-source
Platform-independent
Supports various technologies (having number of native application like: camera, bluetooth, wifi, speech, EDGE)
11. Language Know to develop android apps?
Java
XML
12. Android application main components are?
Components
|
Description
|
Activities
|
They dictate the UI and handle the user interaction to the smartphone screen
|
Services
|
They handle background processing associated with an application.
|
Broadcast Receivers
|
They handle communication between Android OS and applications.
|
Content Providers
|
They handle data and database management issues.
|
13. What is Activities?
An activity is a single, focused thing that the user can do. when ever user click on GUI the next Activity will be start and new GUI set base on coding.
14. What is Intent?
An Intent is exactly what it describes. It's an "intention" to do an action.
An Intent is basically a message to say you did or want something to happen. Depending on the intent, apps or the OS might be listening for it and will react accordingly.
There are two types of intents in android:
- Implicit Intent
- Explicit Intent
15. How to Start Another Activity?
Intent i = new Intent(getApplicationContext(), Activity2.class);
startActivity(i);
Note: you need to past this code on onClick method.
16. Explain Folder, File & Description of Android Apps?
src: This contains the .java source files for your project.
gen: contains the .R file, a compiler-generated file that references all the resources found in your project. You should not modify this file.
bin: contains the Android package files .apk built by the ADT during the build process and everything else needed to run an Android application.
res/drawable-hdpi
This is a directory for drawable objects that are designed for high-density screens.
res/layout
This is a directory for files that define your app's user interface.
res/values
This is a directory for other various XML files that contain a collection of resources, such as strings and colors definitions.
AndroidManifest.xml
This is the manifest file which describes the fundamental characteristics of the app and defines each of its components.
17. What is AVD?
AVD Stand for Android Virtual Device (emulator), The Android SDK includes a mobile device emulator - a virtual mobile device that runs on your computer.
Q.1 Explain in brief about the important file and folder when you create new android application.
When you create android application the following folders are created in the package explorer in eclipse which are as follows:
src: Contains the .java source files for your project. You write the code for your application in this file. This file is available under the package name for your project.
gen —This folder contains the R.java file. It is compiler-generated file that references all the resources found in your project. You should not modify this file.
Android 4.0 library: This folder contains android.jar file, which contains all the class libraries needed for an Android application.
assets: This folder contains all the information about HTML file, text files, databases, etc.
bin: It contains the .apk file (Android Package) that is generated by the ADT during the build process. An .apk file is the application binary file. It contains everything needed to run an Android application.
res: This folder contains all the resource file that is used byandroid application. It contains subfolders as: drawable, menu, layout, and values etc.
Explain AndroidManifest.xmlfile in detail.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.careerride" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:name="com.example.careerride.MainActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The AndroidManifest.xml file contains the following information about the application:
- It contains the package name of the application.
- The version code of the application is 1.This value is used to identify the version number of your application.
- The version name of the application is 1.0
- The android:minSdkVersion attribute of the element defines the minimum version of the OS on which the application will run.
- ic_launcher.png is the default image that located in the drawable folders.
- app_name defines the name of applicationand available in the strings.xml file.
- It also contains the information about the activity. Its name is same as the application name.
Describe android Activities in brief.
Activity provides the user interface. When you create an android application in eclipse through the wizard it asks you the name of the activity. Default name is MainActivity. You can provide any name according to the need. Basically it is a class (MainActivity) that is inherited automatically from Activity class. Mostly, applications have oneor more activities; and the main purpose of an activity is to interact with the user. Activity goes through a numberof stages, known as an activity’s life cycle.
Example:
packagecom.example.careerride; //Application name careerride
importandroid.os.Bundle; // Default packages
importandroid.app.Activity; // Default packages
importandroid.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
When you run the application onCreate method is called automatically.
Describe Intents in detail.
An Android application can contain zero or more activities. If you want to navigate fromone activity to another then android provides you Intent class. This class is available inandroid.content.Intent package.One of the most common uses for Intents is to start new activities.
There are two types of Intents.
Explicit Intents
Implicit Intents
Intents works in pairs: actionand data. The action defines what you want to do, such as editing an item, viewingthe content of an item etc. The dataspecifies what is affected,such as a person in the Contacts database. The data is specified as anUri object.
Explicitly starting an Activity
Intent intent = newIntent (this, SecondActivity.class);
startActivity(intent);
Here SecondActivity is the name of the target activity that you want to start.
Implicitly starting an Activity
If you want to view a web page with the specified URL then you can use this procedure.
Intent i = newIntent(android.content.Intent.ACTION_VIEW,Uri.parse(“http://www.amazon.com”));
startActivity(i);
if you want to dial a telephone number then you can use this method by passing the telephone number in the data portion
Intent i = newIntent (android.content.Intent.ACTION_DIAL,Uri.parse(“tel:+9923.....”));
startActivity(i);
In the above method the user must press the dial button to dial the number. If you want to directly call the number without user intervention, change the action as follows:
Intent i = newIntent (android.content.Intent.ACTION_CALL,Uri.parse(“tel:+9923.....”));
startActivity(i);
If you want to dial tel no or use internet then write these line in AndroidManifest.xml
<uses-permissionandroid:name=”android.permission.CALL_PHONE”/>
<uses-permissionandroid:name=”android.permission.INTERNET”/>
How to send SMS in android? Explain with example.
SMS messaging is one of the basic and important applications on a mobile phone. Now days every mobile phone has SMS messaging capabilities, and nearly all users of any age know how to send and receive suchmessages. Mobile phones come with a built-in SMS application that enables you to send and receiveSMS messages. If you want to send the SMS programmatically then follow the following steps.
Sending SMS Messages Programmatically
Take a button on activity_main.xml file as follows.
<Button android:id="@+id/btnSendSMS" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:onClick=”sendmySMS” android:text="sendSMS" />
According to above code when user clicks the button sendmySMS method will be called. sendmySMS is user defined method.
In the AndroidManifest.xml file, add the following statements
<uses-permissionandroid:name=”android.permission.SEND_SMS”/>
Now we write the final step. Write the given below method in MainActivity,java file
publicvoidsendmySMS(View v)
{
SmsManagersms = SmsManager.getDefault();
sms.sendTextMessage("5556", null, "Hello from careerRide", null, null);
}
In this example I have used two emulator. On the first Android emulator (5554), click the Send SMSbutton to send an SMS message to the second emulator(5556).
Describe the SmsManager class in android.
SmsManager class is responsible for sending SMS from one emulator to another or device.
You cannot directly instantiate this class; instead, you call the getDefault() static method to obtain an SmsManager object. You then send the SMS message using the sendTextMessage() method:
SmsManagersms = SmsManager.getDefault();
sms.sendTextMessage("5556", null, "Hello from careerRide", null, null);
sendTextMessage() method takes five argument.
- destinationAddress — Phone number of the recipient.
- scAddress — Service center address; you can use null also.
- text — Content of the SMS message that you want to send.
- sentIntent — Pending intent to invoke when the message is sent.
- deliveryIntent — Pending intent to invoke when the message has been delivered.
How you can use built-in Messaging within your application?
You can use an Intent object to activate the built-in Messaging service. You have to pass MIME type “vnd.android-dir/mms-sms”, in setType method of Intent as shown in the following given below code.
Intent intent = new Intent (android.content.Intent.ACTION_VIEW);
intent.putExtra("address", "5556; 5558;");// Send the message to multiple recipient.
itent.putExtra("sms_body", "Hello my friends!");
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
What are different data storage options are available in Android?
Different data storage options are available in Android are:
- SharedPreferences
- SQlite
- ContentProvider
- File Storage
- Cloud Storage
Describe SharedPreference storage option with example.
SharedPreference is the simplest mechanism to store the data in android. You do not worry about creating the file or using files API.It stores the data in XML files. SharedPreference stores the data in key value pair.The SharedPreferences class allows you to save and retrieve key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: boolean, floats, int, longs, and strings.The data is stored in XML file in the directory data/data//shared-prefs folder.
Application of SharedPreference
- Storing the information about number of visitors (counter).
- Storing the date and time (when your Application is updated).
- Storing the username and password.
- Storing the user settings.
Example:
For storing the data we will write the following code in main activity on save button:
SharedPreferences sf=getSharedPreferences("MyData", MODE_PRIVATE);
SharedPreferences.Editored= sf.edit();
ed.putString("name", txtusername.getText().toString());
ed.putString("pass", txtpassword.getText().toString());
ed.commit();
In this example I have taken two activities. The first is MainActivity and the second one is SecondActivity.When user click on save button the user name and password that you have entered in textboxes, will be stored in MyData.xml file.
Here MyData is the name of XML file .It will be created automatically for you.
MODE_PRIVATE means this file is used by your application only.
txtusernameand txtpassword are two EditText control in MainActivity.
For retrieving the data we will write the following code in SecondActiviy when user click on Load button:
Public static final String DEFAULT=”N? A”;
DEFAULT is a String type user defined global variable.If the data is not saved in XML file and user click on load button then your application will not give the error. It will show message “No Data is found”. Here name and pass are same variable that I have used in MainActivity.
SharedPreferences sf=getSharedPreferences("MyData", Context.MODE_PRIVATE);
String Uname=sf.getString("name", DEFAULT);
String UPass=sf.getString("pass", DEFAULT);
if(name.equals(DEFAULT)||Pass.equals(DEFAULT))
{
Toast.makeText(this, "No data is found", Toast.LENGTH_LONG).show();
}
else
{
Txtusername.setText(Uname);
Txtpassword.setText(UPass) ;
}
Android test iPhone Android Blackberry iPOD iTouch
Android interview online test (100 questions) -By Pradip Patil, Lecturer IIMP MCA
Android interview questions - posted on June 27, 2013 at 15:29 PM by Kshipra Singh
1. What are the key components of Android Architecture?
Android Architecture consists of 4 key components:
- Linux Kernel
- Libraries
- Android Framework
- Android Applications
2. What are the advantages of having an emulator within the Android environment?
- The emulator allows the developers to work around an interface which acts as if it were an actual mobile device.
- They can write, test and debug the code.
- They are safe for testing the code in early design phase
3. Tell us something about activityCreator?
- An activityCreator is the initial step for creation of a new Android project.
- It consists of a shell script that is used to create new file system structure required for writing codes in Android IDE.
4. What do you know about Intents?
- Notification messages to the user from an Android enabled device can be displayed using Intents. The users can respond to intents.
- There are two types of Intents - Explicit Intent, Implicit Intent.
5. What is an Explicit Intent?
- Explicit intent specifies the particular activity that should respond to the intent.
- They are used for application internal messages.
6. What is an Implicit Intent?
- In case of Implicit Intent, an intent is just declared.
- It is for the platform to find an activity that can respond to it.
- Since the target component is not declared, it is used for activating components of other applications.
7. What do intent filters do?
- There can be more than one intents, depending on the services and activities that are going to use them.
- Each component needs to tell which intents they want to respond to.
- Intent filters filter out the intents that these components are willing to respond to.
8. Where are lay out details placed? Why?
- Layout details are placed in XML files
- XML-based layouts provide a consistent and standard means of setting GUI definition format.
9. What do containers hold?
- Containers hold objects and widgets in a specified arrangement.
- They can also hold labels, fields, buttons, or child containers. .
10. What is Orientation?
- Orientation decides if the LinearLayout should be presented in row wise or column wise fashion.
- The values are set using setOrientation()
- The values can be HORIZONTAL or VERTICAL
11. What is it important to set permissions in app development?
- Certain restrictions to protect data and code can be set using permissions.
- In absence of these permissions, codes could get compromised causing defects in functionality.
12. What is AIDL?
- AIDL is the abbreviation for Android Interface Definition Language.
- It handles the interface requirements between a client and a service to communicate at the same level through interprocess communication.
- The process involves breaking down objects into primitives that are Android understandable.
13. What data types are supported by AIDL?
AIDL supports following data types:
-string
-List
-Map
-charSequence
and
-all native Java data types like int,long, char and Boolean
14. Tell us something about nine-patch image.
- The Nine-patch in the image name refers to the way the image can be resized: 4 corners that are unscaled, 4 edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.
- A Nine-patch image allows resizing that can be used as background or other image size requirements for the target device.
15. Which dialog boxes are supported by android?
Android supports 4 dialog boxes:
a.) AlertDialog: Alert dialog box supports 0 to 3 buttons and a list of selectable elements which includes check boxes and radio buttons.
b.) ProgressDialog: This dialog box is an extension of AlertDialog and supports adding buttons. It displays a progress wheel or bar.
c.) DatePickerDialog: The user can select the date using this dialog box.
d.) TimePickerDialog: The user can select the time using this dialog box.
16. What is Dalvik Virtual Machine?
- It is Android's virtual machine.
- It is an interpreter-only virtual machine which executes files in Dalvik Executable (.dex) format. This format is optimized for efficient storage and memory-mappable execution.
1.What is android? What are the features of Android?
Android is a stack of software for mobile devices which has Operating System, middleware and some key applications..............
2.Why to use Android?
Android is useful because: 1) It is simple and powerful SDK.............
3.Describe Android Application Architecture.
Android Application Architecture has the following components:...........
4.Describe a real time scenario where android can be used
Imagine a situation that you are in a country where no one understands the language you speak and you can not read or write.............
5.What are the advantages of Android?
The following are the advantages of Android: 1) The customer will be benefited from wide range of mobile applications to choose, since the monopoly of wireless carriers like AT&T and Orange will be broken by Google Android.................
6.How to select more than one option from list in android xml file? Give an example.
Specify android id, layout height and width as depicted in the following example............
7.What is needed to make a multiple choice list with a custom view for each row?
Multiple choice list can be viewed by making the CheckBox android:id value be “@android:id /text1"...........
8.What are the dialog boxes that are supported in android? Explain.
Android supports 4 dialog boxes: AlertDialog : An alert dialog box supports 0 to 3 buttons and a list of selectable elements, including check boxes and radio buttons............
9.Explain about the exceptions of Android.
The following are the exceptions that are supported by Android............
TTL is a value in data packet of Internet Protocol. It communicates to the network router whether or not the packet should be in the network for too long or discarded.................
11.What are the differences between a domain and a workgroup?
In a domain, one or more computer can be a server to manage the network. On the other hand in a workgroup all computers are peers having no control on each other.............
12.Explain IP datagram, Fragmentation and MTU.
IP datagram can be used to describe a portion of IP data. Each IP datagram has set of fields arranged in an order. The order is specific which helps to decode and read the stream easily................
13. What are the steps that are involved in converting the android in newer version?
To release a new version requires lots of changes and a process has to be developed to build the changes. The steps that is required:
• In the beginning of the creation the software gets the built or the earlier version of the system image. This includes various certifications and deployment rules and regulations.
• The built goes through operator testing and this is one of the important phase as it allows lot of bugs to be found and corrected.
• The release then goes the regulators, moderators and operators to produce the devices to release the source code. The code that is written is checked for errors and there is a sign of the agreement that take place between the contributors and some verification are performed.
• The production of the software begins and the release process starts and then the release will allow the users to grab the devices.
14. What is the role of compatibility that is used in Android?
The compatibility is defined in terms of android compatible devices that run any application. This application is written by third party developers using the Android platform that comes in the form of SDK and NDK. There are many filters that are used to separate devices that are there to participate in the compatibility mode for the Android applications. The devices that are compatible require the android to approve it for their trademark. The devices that are not passes the compatibility are just given in the Android source code and can use the android trademark. The compatibility is a way through which the user can participate in the Android application platform. The source code is free to use and it can be used by anyone
15. What are the different forms of communication provided by the Android applications?
There are different forms of communication that is used by the Android application developers like:
• Internet telephony: this is used to add SIP-based features to the application. This includes the full SIP protocol stack and includes integrated call management services. These services allow setting the ongoing and incoming voice calls without managing the sessions at the transport level. This provides the communication to be successful by determining the associated carriers.
• NFC (Near field communications) - this is used to allow the communication to happen between the developers that create the new class of application. These new applications are created and provided as a service to the users, organizations, merchants and advertisers. It allows the tagging of application that interests the user. The tag allows the user to communicate through wireless telephony services and allow the use of device hardware.
16. What are the multimedia features involved in making Android popular?
There is the demand for the rich multimedia that involves many features that are used till now to make the Android market more popular in all the phases. The application includes the following:
• Mixable audio effects – developer can easily create audio environments using the API key that is provided with it like creating equalization, bass boost, headphone feature, etc. The android provide the tools that can be used to mix the audio effects and apply it.
• There is also support for new media formats like VP8 open video compression format that uses a container format that can run on all the platforms and add the support for AAC and AMR encoding. The applications provided allow higher quality video to be captured.
• The application allows the access to multiple cameras that allows the use of APIs to include the camera and its properties in one. The platform provides the application to include the camera with high and low resolution.
|
27. What are the security measures that are taken to make Android secure?
Android uses many security measures to keep them away from the hackers. They have designed by making changes to the devices or installing a software service on the mobile. Android application uses sandbox that is very popular and allow limited access to the information that is very private and sensitive for the user. It allows the permissions to be set for the use of the information. The security measures that are provided by android is the use of the encryption of the messages that allow user to remain without worry about there phone security. They also consists of user terms and agreements that also taken care of. Most of the time android doesn't allow other applications to run on their system but it can be done by using different resources that are available on-line. As, android is open source it is not fully secure but lots of security issues are being solved for make it more popular and bug free.
28. Which are the different tags that are required to create reusable user interface that include the layout?
Android offers wide range of user interface widgets through which the reusable user interface can be made. It requires some buttons to be made and also allow multiple widgets to be combined using the single and reusable component. There are XML layout files that are used in which each tag can be mapped to the class instance. The tags that are used are:
• <requestFocus />: this allows the component to remain in focus.
• <merge />: merge the components and their properties into one to create a reusable component code
• <include />: this includes the library files and visual components of XML. This also uses
• <merge /> tag that can be combined with it to create the merging layout.
To create the layout these are the tags that are required and essential. The XML visual components are also used to define the overall structure of the layout.
• <requestFocus />: this allows the component to remain in focus.
• <merge />: merge the components and their properties into one to create a reusable component code
• <include />: this includes the library files and visual components of XML. This also uses
• <merge /> tag that can be combined with it to create the merging layout.
To create the layout these are the tags that are required and essential. The XML visual components are also used to define the overall structure of the layout.
29. Write a program that shows the creation of reusable user interface that includes the layout.
The program that uses the reusable user interface including the layout is given below:
<com.android.launcher.Workspace
android:id="@+id/workspace"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
launcher:defaultScreen="1">
<include android:id="@+id/cell1" layout="@layout/work" />
<include android:id="@+id/cell2" layout="@layout/work" />
</com.android.launcher.Workspace>
The tag that is used in this are:
<include />: this is the element tag and it includes other XML layout files. It calls the layout files by using their name and including @layout. This @ defines the inclusion of layout file in the program. The same out in the example is included two times. The tag overrides some attributes that are included in the layout. The id can be added that uniquely identifies the application and the components that are used inside it.
<com.android.launcher.Workspace
android:id="@+id/workspace"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
launcher:defaultScreen="1">
<include android:id="@+id/cell1" layout="@layout/work" />
<include android:id="@+id/cell2" layout="@layout/work" />
</com.android.launcher.Workspace>
The tag that is used in this are:
<include />: this is the element tag and it includes other XML layout files. It calls the layout files by using their name and including @layout. This @ defines the inclusion of layout file in the program. The same out in the example is included two times. The tag overrides some attributes that are included in the layout. The id can be added that uniquely identifies the application and the components that are used inside it.
30. What are the methods to avoid memory leaks in Android?
Android applications are well bundled with the memory but they have a drawback of running lots of application that keeps in the memory to make the processing faster. The more application in the memory, the faster will be the switch between the applications. The memory leaks can be avoided by changing the context. The context is used for many operations but it is used to access the resources on android. The widgets have a context parameter in their constructors. There are mainly two types of context: either activity or application. The program is as follows:
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
TextView label = new TextView(this);
label.setText("Test memory leak");
setContentView(label);
}
if the context is having leaks in it then the activity then there is a possibility of the leaks of memory. The leaking of the entire activity can be checked. The system will automatically create and destroy one of the activities by default. Android will reload the application by using the rotation policy. And it will keep the entire static field maintained.
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
TextView label = new TextView(this);
label.setText("Test memory leak");
setContentView(label);
}
if the context is having leaks in it then the activity then there is a possibility of the leaks of memory. The leaking of the entire activity can be checked. The system will automatically create and destroy one of the activities by default. Android will reload the application by using the rotation policy. And it will keep the entire static field maintained.
31. What are the steps required to avoid context related memory leaks?
The steps that are required to check and avoid the context-related memory leaks are as follows:
• Never keep the long-lived references linked with the context-activity. This reference can be of the same life as the activity or can be of different length that depends on the type of activity that is getting performed on the action.
• Use of context-application is much better than the context-activity as it allows the application to be reused again and again and the activity can be viewed or executed only once. The application takes less time to execute and activity can take more due to consisting of more than one application in it.
• Non-static inner classes should be avoided while getting used in the activity, as it doesn't control the life-cycle of the static-inner class and make some weak reference to the activities that are inside the process and getting used.
• There should not be relying upon the garbage collector as it is not the ultimate solution for the memory leaks that are defined.
• Never keep the long-lived references linked with the context-activity. This reference can be of the same life as the activity or can be of different length that depends on the type of activity that is getting performed on the action.
• Use of context-application is much better than the context-activity as it allows the application to be reused again and again and the activity can be viewed or executed only once. The application takes less time to execute and activity can take more due to consisting of more than one application in it.
• Non-static inner classes should be avoided while getting used in the activity, as it doesn't control the life-cycle of the static-inner class and make some weak reference to the activities that are inside the process and getting used.
• There should not be relying upon the garbage collector as it is not the ultimate solution for the memory leaks that are defined.
32. What are the steps required in setting up the linkify calls intent?
Linkify is used to route the intent in an activity. This linkify allows the calls to be invoked and allow an activity to be handled. The process of executing the linkfy is as follows:
• linkfy is used to invoke the process in the TextView and allow the matching of the patterns to be turned into the intent links.
• Linkify monitors the intent links that is being selected by the user and allow it to be modified for further actions.
• Linkfy allows the user to select the link and when user selects it, it calls the VIEW action on the content that uses an URI that is associated with the link.
• Android takes the content that is represented by the URI and the data that is used. It looks for the ContentProvider component that is registered with the system and matches the URI of the content that is getting produced.
• If the match is found for the query done by android then the URI gets used by the ContentProvider and MIME type of data can be returned for the URI.
• Android uses the activity registered in the system that uses the intent-filter matching both the VIEW action and the MIME type for the data that can be linked with the URI.
• linkfy is used to invoke the process in the TextView and allow the matching of the patterns to be turned into the intent links.
• Linkify monitors the intent links that is being selected by the user and allow it to be modified for further actions.
• Linkfy allows the user to select the link and when user selects it, it calls the VIEW action on the content that uses an URI that is associated with the link.
• Android takes the content that is represented by the URI and the data that is used. It looks for the ContentProvider component that is registered with the system and matches the URI of the content that is getting produced.
• If the match is found for the query done by android then the URI gets used by the ContentProvider and MIME type of data can be returned for the URI.
• Android uses the activity registered in the system that uses the intent-filter matching both the VIEW action and the MIME type for the data that can be linked with the URI.
Online Test Practice questions