InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 51. |
How to set app_name based on the built type and build flavor? |
|
Answer» For this, we can modify our BUILD Gradle file of the application. In Gradle file we will add CODE for ADDING build TYPE and build flavour like below: buildTypes { debug { applicationIdSuffix '.debug' versionNameSuffix '-DEBUG' resValue "string", "app_name", "AppName debug" } release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release zipAlignEnabled true resValue "string", "app_name", "AppName" } } |
|
| 52. |
How would you access data in a ContentProvider? |
|
Answer» In Android when we WANT to share data between two applications we are using Content Provider. It has a complete mechanism to share data between applications. It will also provide security while sharing data from one application to another application. For getting data from any Content Provider you need to create Content Resolver. For Creating Content Resolver, you need to call ACTIVITY’s getContentResolver method. For Modifying data from Content Provider, you can invoke the basic method of Content Resolver like insert, delete, update and query. These operations are the same as the SQLite DB Operation. Android we have two steps for RETRIEVING data from a Content Provider:
|
|
| 53. |
You’re replacing one Fragment with another — how do you ensure that the user can return to the previous Fragment, by pressing the Back button? |
|
Answer» Android OS provides BACK stack function for Activity, it also provides back stack function for Fragment. If you add ONE Fragment into the back stack, when you PRESS the android device back menu, you can find the Fragment that is saved in back stack popup. Until all saved Fragments in back stack popup, then the activity will exit. We have to create “FragmentTransaction” objects on the back stack and when the user presses the Back BUTTON, the “FragmentManager” pops the most recent transaction off the back stack and performs the reverse action. As mentioned in below code: getSupportFragmentManager().beginTransaction() .add(detailFragment, "DETAIL") // Add this transaction to the back stack .addToBackStack(null) .commit(); |
|
| 54. |
When should you use a Fragment, rather than an Activity? |
|
Answer» In Android, UI is representing as an Activity. Single Screen in an application represents as Activity while FRAGMENTS are reusable UI with business logic. Activity is a collection of Screen. In android application, Fragments are using in Navigation DRAWER in our entire screen. You can also use fragment to display Google Map on screen. Following are important POINTS about a fragment:
|
|
| 55. |
What is a fragment? |
Answer»
|
|
| 56. |
What is a layout? |
Answer»
|
|
| 57. |
What is the purpose of AndroidManifest.xml file? |
|
Answer» It is the FOUNDATION for any Android application. It will be in app module’s src/main/ directory for Android Studio projects. This file contains information of application package, INCLUDING components of the application such as activities, services, broadcast receivers, content providers etc. It performs some other tasks also: It is responsible to protect the application to ACCESS any protected parts by provision of permissions. |
|
| 58. |
What is the recommended way to perform discrete, ‘transactional’ background tasks in Android? |
|
Answer» The recommended way going forward is using WorkManager APIs, that makes it easy to specify deferrable, asynchronous tasks and when they should run under the CIRCUMSTANCES you choose, or RECURRING tasks that run at a specified INTERVAL. Internally WorkManager might use JOBSCHEDULER, Firebase-JobDispatcher, Executor, and AlarmManager for RUNNING the task. |
|
| 59. |
What is ART? |
|
Answer» It stands for Android RUN Time. ART is used for running Android applications. It uses AOT (AHEAD Of Time) compilation on the device. When an APK is getting installed on the Android device, the .dex files from the APK file will be converted to processor’s native instructions set/machine code (.art extension) and that will be stored in the app’s runtime cache directory on the device’s internal storage. This will make installation little bit longer and TAKE more space on the device storage but it makes apps run much faster, less BATTERY consumption, robots application debugging support and better user experience. |
|
| 60. |
How will you terminate an alive thread? |
|
Answer» There is no direct way to terminate a thread but using the two FOLLOWING ways it can be done.
|
|