Android Interview Questions and Answers

Deployment and Process Management

Q1. Why cannot you run standard Java bytecode on Android?
A. Android uses Dalvik Virtual Machine (DVM) which requires a special bytecode. We need to convert Java class files into Dalvik Executable files using an Android tool called "dx". In normal circumstances, developers will not be using this tool directly and build tools will care for the generation of DVM compatible files.
Q2. Can you deploy executable JARs on Android? Which packaging is supported by Android?
A. No. Android platform does not support JAR deployments. Applications are packed into Android Package (.apk) using Android Asset Packaging Tool (aapt) and then deployed on to Android platform. Google provides Android Development Tools for Eclipse that can be used to generate Android Package.
Q3. Android application can only be programmed in Java?
A. False. You can program Android apps in C/C++ using NDK .
Q4. What are Dalvik Executable files?
A. Dalvik Executable files have .dex extension and are zipped into a single .apk file on the device.
Q5. How does Android system track the applications?
A. Android system assigns each application a unique ID that is called Linux user ID. This ID is used to track each application.
Q6. How does an application run in isolation from other applications?
A. Each application gets its own Linux user ID and virtual machine which means that the application code runs in isolation from other applications.
Q7. When does Android start and end an application process?
A. Android starts an application process when application's component needs to be executed. It then closes the process when it's no longer needed (garbage collection).
Q8. How can two Android applications share same Linux user ID and share same VM?
A. The applications must sign with the same certificate in order to share same Linux user ID and share same VM.
Q9. Is it okay to change the name of an application after its deployment?
A. It is not recommended to change the application name after its deployment because this action may break some functionality. For example: shortcuts will not work if you change application name.

Development

Q10. What needs to be done in order to set Android development environment where Eclipse IDE is to be used?
A. Download the Android SDK from Android homepage and set the SDK in the preferences. Windows > Preferences > Select Android and enter the installation path of the Android SDK. Alternatively you may use Eclipse update manager to install all available plugins for the Android Development Tools (ADT).
Q11. Define Android application resource files?
A. As an Android application developer, you can inject files (XML, JSON, JPEG etc) into the build process and can load them from the code. These injected files are revered as resources.
Q12. Which dialog boxes can you use in you Android application?
A. AlertDialog: an alert dialog box and supports 0 to 3 buttons and a list of selectable elements. ProgressDialog: an extension of AlertDialog and you may add buttons to it. It shows a progress wheel or a progress bar. DatePickerDialog: used for selecting a date by the user. TimePickerDialog: used for selecting time by the user.
Q13. Define Activity application component.
A. It is used to provide interactive screen to the users. It can contain many user interface components. A typical Android application consists of multiple activities that are loosely bound to each other. Android developer has to define a main activity that is launched on the application startup.
Q14. Can an Android application access files or resources of another Android application?
A. The system sets permission on all the files/resources of an application so that they are only accessible by their own application. Other applications cannot access resources belonging to other applications unless applications sign the same certificate.
Q15. An Android application needs to access device data e.g SMS messages, camera etc. At what stage user needs to grant the permissions?
A. Application permission must be granted by the user at install time.
Q16. How will you launch an Activity within you application?
A. For launching an application, we will need to create an intent that explicitly defines the activity that we wish to start. For example:
Code
  1.         Intent intent = new Intent(this, MyTestActivity.class);
  2.         startActivity(intent);
Copyright GeekInterview.com
Q17. How can your application perform actions that are provided by other application e.g. sending email?
A. Intents are created to define an action that we want to perform and the launches the appropriate activity from another application.
Code
  1.         Intent intent = new Intent(Intent.ACTION_SEND);
  2.         intent.putExtra(Intent.EXTRA_EMAIL, recipientArray);
  3.         startActivity(intent);
Copyright GeekInterview.com
Q18. What attribute values should be localized?
A. The attribute values that can be displayed to users should be localized. For example: label, icon etc.
Q19. Write code snippet to retrieve IMEI number of Android phone.
A. TelephonyManager class can be used to get the IMEI number. It provides access to information about the telephony services on the device.
Code
  1.         TelephonyManager mTelephonyMgr = (TelephonyManager)
  2.         getSystemService(Context.TELEPHONY_SERVICE);
  3.         String imei = mTelephonyMgr.getDeviceId();
Copyright GeekInterview.com
Q20. How will you call a subactivity? Write code.
A.
Code
  1.         Intent intent = new Intent(this, SubActivity.class);
  2.         addintent.putExtra(name, value);
  3.         startActivityForResult(intent, int);
Copyright GeekInterview.com
Q21. Name the resource that is a compiled visual resource and can be used as a background, title, or in other part of the screen.
A. Drawable is the virtual resource that can e used as a background, title, or in other parts of the screen. It is compiled into an android.graphics.drawable subclass.
Q22. What is an Action?
A. Action in Android glossary is something that an Intent sender wants done. It is a string value that is assigned to intent. Action string can be defined by the Android itself or by you as third party application developer.
Q23. How will you pass data to sub-activities?
A. We can use Bundles to pass data to sub-activities. There are like HashMaps that and take trivial data types. These Bundles transport information from one Activity to another.
Code
  1.         ...
  2.         Bundle b = new Bundle();
  3.         b.putString("EMAIL", "abc@xyz.com");
  4.         i.putExtras(b); // where i is the intent
  5.         ...
Copyright GeekInterview.com

Manifest File

Q24. Where will you declare your activity so the system can access it?
A. Activity is to be declared in the manifest file. For example:
Code
  1.         <manifest></manifest>
  2.          <application></application>
  3.          <activity android:name=".MyTestActivity"></activity>
  4.          ...
  5.          
  6.          ...
  7.        
Copyright GeekInterview.com
Q25. Where can you define the icon for your Activity?
A. Icon for an Activity is defined in the manifest file.
Code
  1.         <activity android:icon="@drawable/app_icon" android:name=".MyTestActivity"></activity>
  2.         ...
  3.        
Copyright GeekInterview.com
 
Android User Questions     Android User Discussion
 

Comments