6 Essential Interview Questions with Answers

1 . What is a ContentProvider and what is it typically used for?

A ContentProvider manages access to a structured set of data. It encapsulates the data and provide mechanisms for defining data security. ContentProvider is the standard interface that connects data in one process with code running in another process.



2. There are four Java classes related to the use of sensors on the Android platform. List them and explain the purpose of each.

The four Java classes related to the use of sensors on the Android platform areL
Sensor: Provides methods to identify which capabilities are available for a specific sensor.
SensorManager: Provides methods for registering sensor event listeners and calibrating sensors.
SensorEvent: Provides raw sensor data, including information regarding accuracy.
SensorEventListener: Interface that defines callback methods that will receive sensor event notifications.

3. Under what condition could the code sample below crash your application? How would you modify the code to avoid this potential problem? Explain your answer.

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage);
    sendIntent.setType(HTTP.PLAIN_TEXT_TYPE); // "text/plain" MIME type
    startActivity(sendIntent);

An implicit intent specifies an action that can invoke any app on the device able to perform the action. Using an implicit intent is useful when your app cannot perform the action, but other apps probably can. If there is more than one application registered that can handle this request, the user will be prompted to select which one to use.

However, it is possible that there are no applications that can handle your intent. In this case, your application will crash when you invoke startActivity(). To avoid this, before calling startActivity() you should first verify that there is at least one application registered in the system that can handle the intent. To do this use resolveActivity() on your intent object:

    // Verify that there are applications registered to handle this intent
    // (resolveActivity returns null if none are registered)
    if (sendIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(sendIntent);
    }

4. The last callback in the lifecycle of an activity is onDestroy(). The system calls this method on your activity as the final signal that your activity instance is being completely removed from the system memory. Usually, the system will call onPause() and onStop() before calling onDestroy(). Describe a scenario, though, where onPause() and onStop() would not be invoked.

onPause() and onStop() will not be invoked if finish() is called from within the onCreate() method. This might occur, for example, if you detect an error during onCreate() and call finish() as a result. In such a case, though, any cleanup you expected to be done in onPause() and onStop() will not be executed.
Although onDestroy() is the last callback in the lifecycle of an activity, it is worth mentioning that this callback may not always be called and should not be relied upon to destroy resources. It is better have the resources created in onStart() and onResume(), and have them destroyed in onStop() and onPause, respectively.

More information about Activity Life Cycle can be found here
   
    5. Describe three common use cases for using an Intent.
Common use cases for using an Intent include:

To start an activity: You can start a new instance of an Activity by passing an Intent to startActivity() method.
To start a service: You can start a service to perform a one-time operation (such as download a file) by passing an Intent to startService().
To deliver a broadcast: You can deliver a broadcast to other apps by passing an Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().

6. What is an Intent? Can it be used to provide data to a ContentProvider? Why or why not?

The Intent object is a common mechanism for starting new activity and transferring data from one activity to another. However, you cannot start a ContentProvider using an Intent.


When you want to access data in a ContentProvider, you must instead use the ContentResolver object in your application’s Context to communicate with the provider as a client. The ContentResolver object communicates with the provider object, an instance of a class that implements ContentProvider. The provider object receives data requests from clients, performs the requested action, and returns the results.

For more Updates to know about Android,Check Here

Comments

Popular posts from this blog

Google Declared Best Android Apps Of 2017: No Place For Facebook Or Whatsapp That Make Everyone Love It

Steps for Android Studio - Environment Setup

Core Building Blocks of Android