Android NDK Interview Questions

General


 

1. What is Android NDK?

Native development Kit as it it called gives you ace

2.  When can the callback implementations to NativeActivity cause an ANR?

Native activity contains all the callback information and data structures.  The main thread handles the callbacks.  So, your callback implementations should not be blocking.  If they block, you may receive an ANR because your main thread is unresponsive until the callback returns.

3.

Android Interview questions

Threads


 1.  During Android unit testing, what is the difficulty in using ‘static’ variables?

Static variables are cleared and set to ‘null’ each time a set of data is called.  This is because your app is reset/killed each time

Solution:  Call super.tearDown() before each test.

2.   What is dependency injection in Android?

Dependency injection is a style of object configuration in which an objects fields and collaborators are set by an external entity.

In Android, Dagger & Guice are examples of dependency injectors:

RoboGuice 2 example:

 

3.  How is Serializable different from Parcel?

Parcels are designed for high performance IPC transport, used heavily in Binders.  For normal serialization concepts, use Serializable.  Serializable is much heavier and takes more time.  Therefore Parcels are used in embedded devices.

4.   What is a Handler, Thread & Loader?

Handler:  A class that can synchronize a worker thread to the main thread.  In the example of ASyncTask, the onProgressUpdate() and the doPostExecute() method are already synchronized.  They are examples of handlers.  You can create your custom handler methods for your custom thread classes.

Thread:  A line of execution.

Loader:

  • It provides asynchronous loading of data.
  • They are available to every Activity and Fragment.
  •  They monitor the data source and deliver new results when contents change.
  • They automatically reload to their last loader cursor when being recreated after a configuration change.  They don’t need to re-query data

5.  What is a looper, message queue and handler?

Looper – part of any Thread to loop through message queue.  This will be used to check if any incoming message has arrived to this thread. Only one looper exists for a given thread. Only for handler threads this looper will be activated, for other normal threads this will be in passive or inactive mode.

Message Queue – part of any thread, will store incoming messages to this thread. For any thread only one message Q is available. Handler – communication channel between two threads.

Handler is associated with Looper. for a given looper we can n number of handlers to communicate with it from out side world.

Memory Leaks


 1.  What are some of the causes for memory leaks in Android?

Leaking a context causes references to an Activity’s view group and all its resources inside it.

2.  What is the most common memory leak in Android?

Screen orientation change.  When this happens,  Android destroys the current activity and creates a new one  preserving its state.   This can cause a leak in the entire Activity and all its references resources.

3.  What is a leak?

Keeping a reference to any object that the garbage collector is unable to collect.

4.  How to avoid Context related leaks?

  • Avoid using non-static inner classes in an activity if instances of the inner class could outlive the activity’s lifecycle. Instead, prefer static inner classes and hold a weak reference to the activity inside.

5. How can you leak a Context?

In Java, non-static inner and anonymous classes hold an implicit reference to their outer class. Static inner classes, on the other hand, do not.

Views


 1.  How do you create a View programmatically without using a View  Inflater service?

Context


 1. What are contexts used for?

Various reasons but mostly to load and access resources.  This is why all widgets have a context parameter.

2.  What are some types of Contexts?

Application Context

An instance of Context that is tied to the lifecycle of the application.

Example:  Use when you need something that is tied to a global scope.  Such as a WakefulIntentService.  To get a static WakeLock you would need a context to PowerManager.  In this case it is safest to use getApplicationContext().

Activity context

An instance of Context that is tied to the lifecycle of an activity.

Usually passed to classes and methods that require a context.   Holds a reference to a Viewgroup and all the resources inside it.   If a context leaks, the entire activity can be leaked since a reference is always held causing a lot of memory to be held up.

Services


1.  What is a started Service?

When this service is started, it has a lifecycle that’s independent of the component that started it and the service can run in the background indefinitely, even if the component that started it is destroyed. As such, the service should stop itself when its job is done by calling stopSelf() or another component can stop it by calling stopService()

2.  What is a bound Service?

You should create a bound service when you want to interact with the service from activities and other components in your application or to expose some of your application’s functionality to other applications, through interprocess communication (IPC).

Application Questions


 1. Photo Sharing App / notification manager attach to a notification object, what would you use

Pending Intent

2. Data from one app to another and if you want some fields hidden

Content Provider

3. If your app has to have messaging as an option, what would you use to navigate to the messaging app.

 

4.  If you want an animation to appear .5 sec after a button click, what would you use?

 

5. Android Service – Does it run on UI thread?

Yes

6.  How do you schedule a recurring task at periodic intervals

Alarm Manager

My Rental Pro

Today’s Featured App

My Rental Pro

mrp_feature_graphic

Ever found the need to manage you rental property the way you want it to be.  An intuitive app that tracks and shows what you need and watch your cash flow grow.

You can use the app to manage all your rental properties, collect rents, track expenses.  If your property has a mortgage on it, the app provides parameters to see how your rents calculate against your existing loan.   The best part of the app is visualizing cash-flow against all values of your property and see how it is doing.

You can also hypothetically model a property and see if it will make money starting this year.

Get it on Google Play

Rails Formtastic – How to remove the unordered list from form inputs

When using ‘Formtastic’ the default behavior is to add an unordered list to the set of inputs.  This is specified in its CSS.   This makes the form look like it has a set of radio bullets.

How to remove this?

From an input:

From a button:

 

How to create a guest user in Rails 4

If you have Devise authentication:

 

 

Redirect to previous page after sign in

When using ‘Devise’ for your authentication mechanism,  you may need to redirect to the previous webpage after signing in.

To do this:

 

Writing an Executive Summary

Executive Summary

An executive summary should contain the following points:

One or two line summary

A concise one to two line depiction of what your company does with its product or service.

Services or Product provided

3. Market definition

4. Risk / Opportunity

5. Competition

6. Capital Requirements

7. Operations

8.  Financial Snapshot

9.  Previous Capital Raises

My Rental Pro

Today’s Featured App

My Rental Pro

mrp_feature_graphic

Ever found the need to manage you rental property the way you want it to be.  An intuitive app that tracks and shows what you need and watch your cash flow grow.

You can use the app to manage all your rental properties, collect rents, track expenses.  If your property has a mortgage on it, the app provides parameters to see how your rents calculate against your existing loan.   The best part of the app is visualizing cash-flow against all values of your property and see how it is doing.

You can also hypothetically model a property and see if it will make money starting this year.

Get it on Google Play

Java Interview Questions

1.  What is the purpose of ‘final’,  ‘finalize’ and ‘finally?

final

final can be used to mark a variable “unchangeable”

final can also make a method not “overrideable”

final can also make a class not “inheritable”. i.e. the class can not be subclassed.

finally

finally is used in a try/catch statement to execute code “always”

finalize

finalize is called when an object is garbage collected. You rarely need to override it. An example:

Android – Handler, Message Queue and Loopers

Looper – part of any Thread to loop through message queue. This will be used to check if any incoming message has arrived to this thread. Only one looper exists for a given thread. Only for handler threads this looper will be activated, for other normal threads this will be in passive or inactive mode.

Message Queue – part of any thread, will store incoming messages to this thread. For any thread only one message Q is available. Handler – communication channel between two threads.

Handler is associated with Looper. for a given looper we can n number of handlers to communicate with it from out side world.