Skip to content

Instantly share code, notes, and snippets.

@hilfritz
Created July 10, 2018 13:41
Show Gist options
  • Select an option

  • Save hilfritz/fc80a533d49d690f6647d472439c8894 to your computer and use it in GitHub Desktop.

Select an option

Save hilfritz/fc80a533d49d690f6647d472439c8894 to your computer and use it in GitHub Desktop.
android questions
https://github.com/MindorksOpenSource/android-interview-questions#data-structures-and-algorithms
https://www.toptal.com/android/interview-questions
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.
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);
Fix: //could cause a crash, cos the intent may not exist (ex. No pdf reader installed)
// Verify that there are applications registered to handle this intent
// (resolveActivity returns null if none are registered)
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(sendIntent);
}
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.
Describe three common use cases for using an Intent. (Can provide as many as possible)
- 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().
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.
What is the difference between a fragment and an activity? Explain the relationship between the two.
-
What is difference between Serializable and Parcelable ? Which is best approach in Android ?
- Serializable is a standard Java interface. You simply mark a class Serializable by implementing the interface, and Java will automatically serialize it in certain situations.
- Parcelable is an Android specific interface where you implement the serialization yourself. It was created to be far more efficient than Serializable, and to get around some problems with the default Java serialization scheme.
What is the difference between Service and IntentService? How is each used?
- Service is the base class for Android services that can be extended to create any service. A class that directly extends Service runs on the main thread so it will block the UI (if there is one) and should therefore either be used only for short tasks or should make use of other threads for longer tasks.
- IntentService is a subclass of Service that handles asynchronous requests (expressed as “Intents”) on demand. Clients send requests through startService(Intent) calls. The service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work. Writing an IntentService can be quite simple; just extend the IntentService class and override the onHandleIntent(Intent intent) method where you can manage all incoming requests.
What is ANR, and why does it happen?
‘ANR’ in Android is ‘Application Not Responding.’ It means when the user is interacting with the activity, and the activity is in the onResume() method, a dialog appears displaying “application not responding.”
It happens because we start a heavy and long running task like downloading data in the main UI thread. The solution of the problem is to start your heavy tasks in the backbround using Async Task class
Is it possible to create an activity in Android without a user interface ?
- Yes, an activity can be created without any user interface. These activities are treated as abstract activities.
User clicks back button, which life cycle methods will be called for activity?
ans : onpause, onstop, ondestroy.
How do you save/edit/delete/update data? You can name libraries, or any of the Android framework library.
- sqlite, shared preferences, files,
2. types of services?
ans : Service & IntentService
What do you use to start an activity?
Bonus:
Which method is called only once in a fragment life cycle?
- onAttached()
How many hours do you spend on coding every day?
Database used?
Architecture
Describe the architecture of your last app.
How do you handle threads? Between ui thread and background/worker thread?
How do you like Reactive programming? (Can mention library names)
Have you used unit testing?
Have you tried Kotlin?
What are the device hardware you have used?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment