ANDROID BASICS PART III
1. What is Broadcast Receiver?
· A broadcast receiver is a
component that does nothing but receives and reacts to broadcast announcements.
· Many broadcasts originate in
system code — for example, announcements that the time zone has changed, that
the battery is low, that a picture has been taken, or that the user changed a
language preference.
· Applications can also initiate
broadcasts — for example, to let other applications know that some data has
been downloaded to the device and is available for them to use.
Sincere Thanks to Source:
http://stackoverflow.com/questions/3564265/what-is-the-use-of-broadcast-receiver-in-android
http://stackoverflow.com/questions/3564265/what-is-the-use-of-broadcast-receiver-in-android
2.
What is Content Provider?
· Android provides multiple ways for different apps to communicate amongst themselves on the platform.
· Android provides multiple ways for different apps to communicate amongst themselves on the platform.
· An Android app can share data with other apps
that can be used by other apps to build their own logic around.
· To give an example, you might need to query
contact details on the phone. In Android the recommended way to share data is
through content providers.
· A content provider is an owner of particular
content, it provides well defined APIs to read, insert, update and delete that
data.
· The
content provider can internally use any place to store its data like a local
file, local database or some remote service.


Sincere Thanks to Sources:
3. What is View
and View Group in Android?
·
The Android View class and ViewGroup class are
two very central classes in Android apps.
·
An Android app contains one or more activities.
·
An Android activity is a screen, similar to
windows in a desktop application.
·
Inside an activity you can have GUI components.
·
The GUI components are instances of View or
ViewGroup subclasses.
·
It may sound a bit abstract at this point, but I
will explain both in more detail below.
View:
·
The View class is a superclass for all GUI
components in Android.
· For instance, the TextView class which is used
to display text labels in Android apps is a subclass of View.
Android
contains the following commonly used View subclasses:
·
TextView
·
EditText
·
ImageView
·
ProgressBar
·
Button
·
ImageButton
·
CheckBox
·
DatePicker
These are
only some of the many, many subclasses of the View class.
ViewGroup
·
The ViewGroup class is a subclass of the View
class.
·
ViewGroup instances work as containers for View
instances to group View instances together.
Android
contains the following commonly used ViewGroup subclasses:
·
LinearLayout
·
RelativeLayout
·
ListView
·
GridView
These are not the only ViewGroup subclasses Android contains. There are
others but which are less used.
The
ViewGroup subclasses listed above group View instances together and takes care
of their layout. For instance, the LinearLayout will render the components
after each other either horizontally or vertically.
Sincere Thanks to Sources:
4. What is View
Pager?
· The ViewPager is the widget that allows the user
to swipe left or right to see an entirely new screen.
· In a sense, it's just a nicer way to show the
user multiple tabs. It also has the ability to dynamically add and remove pages
(or tabs) at any time.
With the
ViewPager, the user could then swipe left or right to see other categorized
lists
Sincere Thanks to Source:
5.
What is
ActionBar ?
I think, it can be best
explained here:
6. Navigation Drawer -
The navigation drawer
is a panel that displays the app’s main navigation options on the left edge of
the screen.
It is hidden most of the time, but is revealed
when the user swipes a finger from the left edge of the screen or, while at the
top level of the app, the user touches the app icon in the action bar.
Sincere Thanks to Source:
7. Which dialog
boxes are supported by android?
Android supports 4 dialog boxes
ü
AlertDialog
ü
ProgressDialog
ü
DatePickerDialog
ü
TimePickerDialog
ü AlertDialog
An alert dialog box supports 0 to 3 buttons
and a list of selectable elements, including check boxes and radio buttons.
Among the other dialog boxes, the most suggested dialog box is the alert dialog
box.
ü ProgressDialog
This dialog box displays a progress wheel or
a progress bar. It is an extension of AlertDialog and supports adding buttons.
ü DatePickerDialog
This dialog box is used for selecting a date
by the user.
ü TimePickerDialog
This dialog box is used for selecting time by
the user.
8.
Explain about Naming Conventions in Android?
9. What do
you mean by Containers
·
Holds objects and widgets in a specified
arrangement.
·
They can also hold labels, fields, buttons, or
child containers.
10.
Explain
ANR - ANR Notification in Android
· ANR - Application Not Responding
· Android systems show this dialog if the
application is performing too much of task on the main thread and been
unresponsive for a long period of time.
· As it takes long time for the main thread to
complete the task, the work should be divided and another thread named as child
thread be used for executing more tasks, as it takes less time.
· Main thread should provide handler for child
threads to post back upon completion
· The ANR dialog is displayed to the user based
on two possible conditions. One is when there is no response to an input event
within 5 seconds, and the other is when a broadcast receiver is not done
executing within 10 seconds.
11. Explain about the exceptions of Android?
·
InflateException
:
When an error conditions are occurred, this exception is thrown
· Surface.OutOfResourceException: When a
surface is not created or resized, this exception is thrown
· SurfaceHolder.BadSurfaceTypeException:
This exception is thrown from the lockCanvas() method, when invoked on a Surface whose is
SURFACE_TYPE_PUSH_BUFFERS
This exception is thrown from the lockCanvas() method, when invoked on a Surface whose is
SURFACE_TYPE_PUSH_BUFFERS
·
WindowManager.BadTokenException:
This exception is thrown at the time of trying to add view an invalid WindowManager.LayoutParamstoken
This exception is thrown at the time of trying to add view an invalid WindowManager.LayoutParamstoken
12. How do you
solve compatibility issues?
·
Use dp (density
independent pixels) in place of px for view width and height.
·
Create various
density image with same name for drawable- mdpi, hdpi, xhdpi, xxhdpi.
·
Use nine-patch
images for better scaling without blur effect.
·
Avoid hard coded
width and height values, and always give width and height with respect to
parent.
·
Use fragments if you
are targeting your application for both mobiles and tablets.
13.
Storage
Methods in Android:
·
Shared
Preferences Store
private primitive data in key-value pairs.
·
Internal
Storage Store private
data on internal memory
·
External
Storage Store public data on the shared
external storage
·
SQLite
Databases Store structured data in a
private database
·
Network
Connection Store data on the web with your
own network server.
14.
Describe
Shared Preference storage option with example.
·
Shared Preference 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.
·
Shared Preference stores the data in key value
pair.
·
The Shared Preferences class allows you to
save and retrieve key-value pairs of primitive data types.
·
You can use Shared Preferences 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
15. Application
of Shared Preference.
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.
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) ;
}
Extended Question :
G1.What do you mean by structured,
non-structured data and semi-structured data?
View all answers of extended questions on this page –
http://techendu.blogspot.in/p/android-basics-ex.html?m=1
16.
What do
you mean by localization?
Localization is a way of representing the products in different languages.
Android
is an operating system which runs in many regions, so to reach different users
localization is a must.
Localization
in Android can be achieved by incorporating different languages in the
application which you are using.
To
do this knowledge of Java, XML elements, Activity lifecycle and general
principles of internationalization and localization are required.
17.
How does
Android system track the applications
Android
system assigns each application a unique ID that is called Linux user ID. This
ID is used to track each application.
18.
How do you
find IMEI and IMSI number of an Android device
I think,
this link provides a good answer:
19.
Write code
snippet to retrieve IMEI number of Android phone
·
TelephonyManager class can be used to get the
IMEI number.
·
It provides access to information about the
telephony services on the device.
TelephonyManager
mTelephonyMgr = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
String
imei = mTelephonyMgr.getDeviceId();
20.
What are
Best Practice Guidelines for developing quality mobile applications?
I think,
this link provides a good answer:
21.
What is
nine-patch image
·
Image name "nine-patch" refers to
the way the image can be resized
·
It is a resizable bitmap resource that can be
used for backgrounds or other images on the device.
· The NinePatch class permits drawing a bitmap
in nine sections.
· The nine patch images has extension as 9 png
.It allows extension in 9 ways e.g 4 corners that are unscaled ,4 edges that
are scaled in 1 axis , and the middle one that can be scaled into both axes
· In general, a Nine-patch image allows resizing
that can be used as background or other image size requirements for the target
device.
Sincere Thanks to Sources:
Find More Here:
No comments:
Post a Comment