1. What is dependency injection?
SHOW/HIDE ANSWER
Is a pattern for resolving dependency. It is an implementation of dependency inversion principle (DIP).
Some of the libraries to enable dependency injection for are,
- AndroidAnnotations
- Butter Knife
- Dagger
- Dagger2
- RoboGuice
2. How to set permission for content provider?
SHOW/HIDE ANSWER
Read-write permission can be set in the attribute android:permission of provider tag
Read permission can be set in android:readPermission
Write permission can be set in android:writePermission
URI level permission can be set using path-permission tag
Use android:grantUriPermissions to grant temporary permission
Reference
http://developer.android.com/guide/topics/providers/content-provider-creating.html#Permissions
Read permission can be set in android:readPermission
Write permission can be set in android:writePermission
URI level permission can be set using path-permission tag
Use android:grantUriPermissions to grant temporary permission
Reference
http://developer.android.com/guide/topics/providers/content-provider-creating.html#Permissions
3. What are the different protection levels in permission?
SHOW/HIDE ANSWER
http://developer.android.com/guide/topics/manifest/permission-element.html
- normal : The default value, is automatically granted at installation time
- dangerous : Displays it to the user at installation/run-time for their confirmation
- signature : Grants if the requesting application is signed with the same certificate as the application that declared the permission
- signatureOrSystem : Grants if installed in the system image or signature(c)
http://developer.android.com/guide/topics/manifest/permission-element.html
4. What is a ViewStub?
SHOW/HIDE ANSWER
A ViewStub is an invisible, zero-sized View that can be used to lazily inflate layout resources at runtime.
When a ViewStub is made visible, or when inflate() is invoked, the layout resource is inflated. The ViewStub then replaces itself in its parent with the inflated View or Views.
Therefore, the ViewStub exists in the view hierarchy until setVisibility(int) or inflate() is invoked.
Reference
http://developer.android.com/reference/android/view/ViewStub.html
When a ViewStub is made visible, or when inflate() is invoked, the layout resource is inflated. The ViewStub then replaces itself in its parent with the inflated View or Views.
Therefore, the ViewStub exists in the view hierarchy until setVisibility(int) or inflate() is invoked.
Reference
http://developer.android.com/reference/android/view/ViewStub.html
5. What is the use of merge tag in layout?
SHOW/HIDE ANSWER
merge tag can be used for optimizing the layout. When a layout is included in another one; it is useful in removing unnecessary layout that are just used to wrap views.
Reference
http://developer.android.com/training/improving-layouts/reusing-layouts.html#Merge
http://developer.android.com/training/improving-layouts/reusing-layouts.html#Merge
6. Which is the best place to register and unregister a BroadcastReceiver from an Activity?
7. What is the difference between DVM(Dalvik Virtual Machine) and JVM(Java Virtual Machine)?
SHOW/HIDE ANSWER
DVM is register based and is designed to run on low memory devices.
JVM is stack based. The main objective when JVM was designed is to make it run as many platform as possible.
DVM requires less instruction set.
.dex file which DVM can understand is lesser in size compared to .class files.
JVM is stack based. The main objective when JVM was designed is to make it run as many platform as possible.
DVM requires less instruction set.
.dex file which DVM can understand is lesser in size compared to .class files.
8. What is a 9 patch image?
SHOW/HIDE ANSWER
Is a stretchable image that helps in solving compatibility issues when used with devices with different screen sizes.
Here an image is divided into 9 parts,
4 corners - Do not scale
2 vertical edges - Scale vertically
2 horizontal edges - Scale horizontally
1 Middle area - Scale vertically and horizontally
Reference
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
Here an image is divided into 9 parts,
4 corners - Do not scale
2 vertical edges - Scale vertically
2 horizontal edges - Scale horizontally
1 Middle area - Scale vertically and horizontally
Reference
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
9. Under what license Android is released?
SHOW/HIDE ANSWER
Android is released under Apache Software License, Version 2.0("Apache 2.0"). Linux kernel patches are under the GPLv2 license.
Reference
https://source.android.com/source/licenses.html
https://source.android.com/source/licenses.html
10. What is a SparseArray?
SHOW/HIDE ANSWER
SparseArrays are used to map integers to Objects. It is called sparse because there can be gaps in the indices.
It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping. Reference
http://developer.android.com/reference/android/util/SparseArray.html
It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping. Reference
http://developer.android.com/reference/android/util/SparseArray.html
11. What is an ArrayMap?
SHOW/HIDE ANSWER
ArrayMap is a generic key->value mapping data structure that is designed to be more memory efficient than a traditional HashMap.
It keeps its mappings in an integer array of hash codes for each item, and an Object array of the key/value pairs.
ArrayMap uses binary search on the integer array to find a key.
Reference
http://developer.android.com/reference/android/util/ArrayMap.html
It keeps its mappings in an integer array of hash codes for each item, and an Object array of the key/value pairs.
ArrayMap uses binary search on the integer array to find a key.
Reference
http://developer.android.com/reference/android/util/ArrayMap.html
12. What is Autoboxing?
SHOW/HIDE ANSWER
Is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes, such as int and Integer
Reference
https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html
https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html
13. How memory trimming can be done in Android?
SHOW/HIDE ANSWER
Implement ComponentCallbacks2, register it using registerComponentCallbacks on your Activity, Service, ContentProvider, or Application and listen for onTrimMemory callback.
onTrimMemory is called with different memory levels some of them are,
TRIM_MEMORY_RUNNING_MODERATE : The device is beginning to run low on memory
TRIM_MEMORY_RUNNING_LOW : The device is running much lower on memory
TRIM_MEMORY_RUNNING_CRITICAL : The device is running extremely low on memory
Reference
http://developer.android.com/reference/android/content/ComponentCallbacks2.html
onTrimMemory is called with different memory levels some of them are,
TRIM_MEMORY_RUNNING_MODERATE : The device is beginning to run low on memory
TRIM_MEMORY_RUNNING_LOW : The device is running much lower on memory
TRIM_MEMORY_RUNNING_CRITICAL : The device is running extremely low on memory
Reference
http://developer.android.com/reference/android/content/ComponentCallbacks2.html
14. What is StrictMode?
SHOW/HIDE ANSWER
StrictMode is a developer tool that can be used to detect accidental disk or network access on the application's main thread.
Reference
http://developer.android.com/reference/android/os/StrictMode.html
1
2
3
4
5
6
| StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() // or .detectAll() for all detectable problems .penaltyLog() .build()); |
http://developer.android.com/reference/android/os/StrictMode.html
15. What are the ways of optimizing layout?
SHOW/HIDE ANSWER
Use Tools(Hierarchy Viewer/Lint) to measure and identifying the bottleneck
Change deeper layouts to flat or wide
Use ViewStub for displaying On Demand
Reference
http://developer.android.com/training/improving-layouts/index.html
Change deeper layouts to flat or wide
Use ViewStub for displaying On Demand
Reference
http://developer.android.com/training/improving-layouts/index.html
16. How to optimize ListView?
SHOW/HIDE ANSWER
http://developer.android.com/training/improving-layouts/smooth-scrolling.html http://blog.trsquarelab.com/2015/12/introduction-to-android-recyclerview.html
- Use background thread to load ListView data
- User View Holder pattern
http://developer.android.com/training/improving-layouts/smooth-scrolling.html http://blog.trsquarelab.com/2015/12/introduction-to-android-recyclerview.html
17. What is RecyclerView?
SHOW/HIDE ANSWER
RecyclerView can be used to display large data much like ListView.
In RecyclerView we can set custom layout management for its children's, it has animation support built-in, has item decorator support and it uses the View-holder pattern.
Reference
http://blog.trsquarelab.com/2015/12/introduction-to-android-recyclerview.html
In RecyclerView we can set custom layout management for its children's, it has animation support built-in, has item decorator support and it uses the View-holder pattern.
Reference
http://blog.trsquarelab.com/2015/12/introduction-to-android-recyclerview.html
18. What is JobScheduler?
SHOW/HIDE ANSWER
An API for scheduling jobs against the framework that will be executed in your application's own process and in main thread.
To use job JobScheduler,
http://developer.android.com/reference/android/app/job/JobScheduler.html http://developer.android.com/reference/android/app/job/JobService.html http://developer.android.com/reference/android/app/job/JobInfo.html
- Create a JobServer implementation: by extending JobService
- Create JobInfo : Use JobInfo.Builder
- Get the JobScheduler : Context.getSystemService(Context.JOB_SCHEDULER_SERVICE)
- schedule the job : JobScheduler.schedule
http://developer.android.com/reference/android/app/job/JobScheduler.html http://developer.android.com/reference/android/app/job/JobService.html http://developer.android.com/reference/android/app/job/JobInfo.html
19. How to create application that support different languages?
SHOW/HIDE ANSWER
create additional values directories inside res/ that include a hyphen and the ISO language code at the end of the directory name.
Keep the language specific string resources into the corresponding directory.
http://developer.android.com/training/basics/supporting-devices/languages.html
Keep the language specific string resources into the corresponding directory.
MyProject/ res/ values/ strings.xml values-es/ strings.xml values-fr/ strings.xmlReference
http://developer.android.com/training/basics/supporting-devices/languages.html
20. How to create application that support different screen sizes?
SHOW/HIDE ANSWER
Create different layout folder according to the screen sizes.
http://developer.android.com/training/basics/supporting-devices/screens.html
MyProject/ res/ layout/ # default (portrait) main.xml layout-land/ # landscape main.xml layout-large/ # large (portrait) main.xml layout-large-land/ # large landscape main.xmlCreate different bitmaps according to the screen densities.
MyProject/ res/ drawable-xhdpi/ awesomeimage.png drawable-hdpi/ awesomeimage.png drawable-mdpi/ awesomeimage.png drawable-ldpi/ awesomeimage.pngReference
http://developer.android.com/training/basics/supporting-devices/screens.html
Howdy Mate,
ReplyDeleteGrazie! Grazie! Grazie! Your blog is indeed quite interesting around advanced android interview questions! I agree with you on lot of points!
A subset of a natural language contains these sentences:
1) Triangle ABC.
2) Line Segment AB.
3) Angle A.
In this set, names of triangles are formed by putting three letters together,
all drawn from the alphabet {A,B,C,D,E}. Line segment names are defined by
putting two letters together from the previous alphabet. And angle names are
(suprise!) given by any letter in that alphabet.
Great effort, I wish I saw it earlier. Would have saved my day :)
Thank you,