1

What is empty process in android and what is its priority?

  • Empty process - an app with out any components in it.
  • Empty process- an app which is destroyed and still in the memory.
  • Empty process - an app which is destroyed and removed from the memory.
  • Empty process - an app with out any components, but always in memory.

Answer: B Empty process- an app which is destroyed and still in the memory.
Description: Empty process - is an application which user is frequently visiting and closing. (Which resides in memory even after killing).
To launch frequently visited app fastly, even after destroying that app, it will be still in memory so that loading time will be reduced and user feels more comfortable. That is called as empty process.
its priority is 5 (Empty_Process). this is the last and least priority of an application or a process.

When android device goes out of memory, to reclaim some memory android will start killing all the processes starting with least priority process. Empty process is the most susceptible process to be killed in case of low memory.

2

Can I have more than one application in a given task?

  • task is different and application is different
  • task can have maximum 1 app
  • task can have n number of apps

Answer: C task can have n number of apps
Description: task is a collection of apps that user traverse when performing some task.
eg: while sending message, he starts with messaging application, and may move to gallery or camera to attach some photo that message. in this scenario messaging and gallery are two different apps. but for user he is doing single task only.

3

Can I have more than one process in a given task?

  • Yes a task can have multiple process in it
  • Task can have only one process
  • Task can have apps not processes

Answer: A Yes a task can have multiple process in it
Description: Apps and process is same. Task is a collection of one or more applications. App means process, so task can contain multiple processes.

4

Do all the activities and services of an application run in a single process?

  • i. Activity & service runs in its own independent process
  • ii. Activities, services and other components of an applications runs in single process.
  • iii. Option 2 is not true always, there can be some situations where we can allow a component of application to run in a different process.
  • iv. option 3 is true only if user id of those two processes are same.
  • i
  • ii
  • iii
  • iv

Answer: D iv
Description: Activities, services and other components of an applications runs in single process. there can be some situations where we can allow a component of application to run in a different process. but this is possible only if user id of those two different processes are same.

5

What is sleep mode in android? What will happen to CPU once screen (LCD) light goes off?

  • Sleep mode - is phone switched off. CPU will not work when LCD is turned off.
  • Sleep mode - means CPU will be sleeping. CPU will not work when LCD is turned off.
  • Sleep mode - means CPU will be sleeping. CPU will go to sleep mode with in fraction of seconds after LCD is turned off.
  • Sleep mode - means CPU will be sleeping and will not accept any command except from RIL(Radio Interface Layer) and alarms. CPU will go to sleep mode with in fraction of seconds after LCD is turned off.

Answer: D Sleep mode - means CPU will be sleeping and will not accept any command except from RIL(Radio Interface Layer) and alarms. CPU will go to sleep mode with in fraction of seconds after LCD is turned off.
Description: There is small difference in power consumption when you compare a phone with laptops.
Laptops most of the times runs on direct power through charger. (Mostly we carry charge with laptop).
Mobiles mostly run on battery power. (Rarely we carry charger with us).
By keeping this in mind, android has designed in a such a way that, phone will not consume battery power if user is not interacting with the phone. This is to increase battery back up time for user.
Thats why when LCD screen power is off (that means user is not interacting with phone), with in fraction of seconds CPU will also go to a mode (sleep mode) where it does minimal work and saves battery power. When CPU is in sleep mode, it accepts commands only from RIL (radio interface layer) which is basically sms and call functions, and alarms. Other than this CPU will stop executing other applications functions.

Note : If any application wants CPU time for its emergency work when CPU is in sleep mode, then it can request CPU time by using WAKE LOCKS.
For eg : MP3 application has to keep playing songs in its service, even though user has turned off LCD screen. That means MP3 application's service has requested CPU time by using WAKE LOCKS.

6

How many kinds of wake locks are available, which one to use when?

  • PARTIAL_WAKE_LOCK - use it when you need only screen
    SCREEN_DIM_WAKE_LOCK - use it when you need only CPU on
    SCREEN_BRIGHT_WAKE_LOCK - use it when you need screen Bright
    FULL_WAKE_LOCK - use it when you need all SCREEN, CPU, Keypad in bright and on.
  • PARTIAL_WAKE_LOCK - use it when you need only CPU on
    SCREEN_DIM_WAKE_LOCK - use it when you need only Screen on
    SCREEN_BRIGHT_WAKE_LOCK - use it when you need screen & keyboard Bright
    FULL_WAKE_LOCK - use it when you need all SCREEN, CPU, Keypad in bright and on.
  • PARTIAL_WAKE_LOCK - use it when you need only CPU on
    SCREEN_DIM_WAKE_LOCK - use it when you need CPU + Screen in dim mode
    SCREEN_BRIGHT_WAKE_LOCK - use it when you need CPU + keyboard Bright
    FULL_WAKE_LOCK - use it when you need all SCREEN, CPU, Keypad in bright and on.
  • PARTIAL_WAKE_LOCK - use it when you need only CPU on
    SCREEN_DIM_WAKE_LOCK - use it when you need CPU + Screen in dim mode
    SCREEN_BRIGHT_WAKE_LOCK - use it when you need CPU + SCREEN Bright
    FULL_WAKE_LOCK - use it when you need all SCREEN, CPU, Keypad in bright and on.

Answer: D PARTIAL_WAKE_LOCK - use it when you need only CPU on
SCREEN_DIM_WAKE_LOCK - use it when you need CPU + Screen in dim mode
SCREEN_BRIGHT_WAKE_LOCK - use it when you need CPU + SCREEN Bright
FULL_WAKE_LOCK - use it when you need all SCREEN, CPU, Keypad in bright and on.
Description: There are 4 types of wake locks available in android power manager driver:
1. PARTIAL_WAKE_LOCK - use it when you need only CPU to be on
eg : while traveling playing mp3 audio songs, which requires only cpu to be on.
2. SCREEN_DIM_WAKE_LOCK - use it when you need CPU and Screen in dim mode
3. SCREEN_BRIGHT_WAKE_LOCK - use it when you need CPU and SCREEN in Bright mode
eg : while traveling if we want to watch a movie in the phone, then both cpu & screen should be on.
4. FULL_WAKE_LOCK - use it when you need all SCREEN, CPU, Keypad in bright and on.
eg : If user is playing a game, then cpu, screen lights, and keypads lights should be on.
Because to play a game, user might be using keyboard also to navigate or to move the elements in the game.

7

while using full wake lock and user presses screen lights off (power button), then what will happen?

  • Still Screen lights will be on forcefully.
  • Screen lights & Keyboard will be off, but CPU still running.
  • Screen lights will be off, and CPU also go to sleep.
  • Screen lights will be off, and CPU also go to sleep
  • Screen lights & keyboards lights will be off, but CPU still running.

Answer: B Screen lights & Keyboard will be off, but CPU still running.
Description: Screen lights & Keyboard will be off, but CPU still running.

8

When phone is in sleep mode, what are the two components that will keep running even though phone is in sleep mode?

  • RIL (Radio Interface Layer) & time ticks
  • RIL (Radio Interface Layer) & alarms
  • only Call Manager & alarms
  • only call manager, sms manager, and alarms

Answer: B RIL (Radio Interface Layer) & alarms

Description: Complete RIL layer( SMS, Data pockets, and Calls) & alarms will be still running even in sleep mode also.

Note : But remember all alarms will be destroyed once user switches off the phone.

9

Every day night at 12 o clock I need to post some images to Facebook, in that case I will set repeating alarm for every day night 12 am. But to upload images I want to start service, how should I do this ?

  • Create a pending intent to start a service, and give it to alarm to fire at every day night 12.
  • Create a pending intent to start a service, and give it to alarm to fire at every day night 12. Also make sure to acquire full wake lock in onCreate of your service and release wake lock after uploading all images.
  • Create a pending intent to start a service, and give it to alarm to fire at every day night 12. Also make sure to acquire partial wake lock in onCreate of your service and release wake lock after uploading all images.
  • option 3 is wrong and option 2 is correct, because partial wake lock may not be available for full period of time.

Answer: B Create a pending intent to start a service, and give it to alarm to fire at every day night 12. Also make sure to acquire full wake lock in onCreate of your service and release wake lock after uploading all images.
Description: Create a pending intent to start a service, and give it to alarm to fire at every day night 12. Also make sure to acquire full wake lock in oncreate of your service and release wake lock after uploading all images. Only for broadcast receivers tied up with alarms, will hold wake locks automatically. but if you are starting a service from alarm, them alarm manager wont hold wake lock for you. it is programmers duty to hold wake locks in service.

10

Show with one example where memory leak possibility in Android?

  • class MyActivity extends Activity
    {
    private static Drawable sBackground;

    @Override
    protected void onCreate(Bundle state) {
    super.onCreate(state);

    TextView label = new TextView(this);
    label.setText("Leaks are bad");

    if (sBackground == null) {
    sBackground = getDrawable(R.drawable.large_bitmap);
    }

    label.setBackgroundDrawable(sBackground);
    setContentView(label);
    }
  • class MyActivity extends Activity
    {
    private static Drawable sBackground;

    @Override
    protected void onCreate(Bundle state) {
    super.onCreate(state);

    TextView label = new TextView(getApplicationContext());
    label.setText("Leaks are bad");

    if (sBackground == null) {
    sBackground = getDrawable(R.drawable.large_bitmap);
    }

    label.setBackgroundDrawable(sBackground);
    setContentView(label);
    }
  • class MyActivity extends Activity
    {
    private static Drawable sBackground;
    TextView label;

    @Override
    protected void onCreate(Bundle state) {
    super.onCreate(state);

    label = new TextView(this);
    label.setText("Leaks are bad");
    if (sBackground == null) {
    sBackground = getDrawable(R.drawable.large_bitmap);
    }

    label.setBackgroundDrawable(sBackground);
    setContentView(label);

    onDestroy()
    {
    label.unbindDrawables()
    }
    }
  • All above leaks memory.

Answer: A class MyActivity extends Activity
{
private static Drawable sBackground;

@Override
protected void onCreate(Bundle state) {
super.onCreate(state);

TextView label = new TextView(this);
label.setText("Leaks are bad");

if (sBackground == null) {
sBackground = getDrawable(R.drawable.large_bitmap);
}

label.setBackgroundDrawable(sBackground);
setContentView(label);
}
Description: First option, where static drawables are bound with process life cycle, which is pointing to label, which pointing to activity context. This is kind of dead lock situation where Android can't clean activity's resources because activity's pointer is held by label which can't be cleaned because it is pointed by process global data (static variables) drawable.

11

If I want to write one application for both phones and tablets, what should I use in my UI?

  • i. Use fragments where ever it is possible , Use pixels instead of DPs , Use xhdpi images as well.
  • ii. Use fragments where ever it is possible, Use Dps instead of pixels, Use xhdpi images as well.
  • iii. try to avoid giving margins based on pixels, rather use margins with respect to parent
  • i
  • ii
  • i & iii
  • ii & iii

Answer: D ii & iii
Description: 1. Use fragments where ever it is possible 2. Use Dps instead of pixels 3. Use xhdpi images as well.4. avoid giving margins based on pixels, rather use margins with respect to parent 5. Use SPs for font sizes. 6. Use 9 patch images always.

12

I have a thousands of items in my array, and I want to display it in listview, what is the most optimized way to achieve this?

  • i. getView() function of customadapter which returns the view for each row, some times can be reused. Just check if it is not null, then re-use it.
  • ii. If you are accessing data from network or SQL table, make sure you use different thread to do it, to avoid over head on Main Thread.
  • iii. Use ViewHolder instead of using findViewById() to find different views while inflating the data in getView of custom adapter.
  • iv. Use predefined black color background for your list view, to avoid redrawing over head on android.
  • i
  • i & ii
  • i, ii, & iii
  • i, ii, iii, & iv

Answer: D i, ii, iii, & iv
Description: All the above mentioned 4 options can be used to optimize and load items quickly.

13

How many processes, and Virtual machines will be given for each application, by android system?

  • One process, and one common Virtual machine for all applications.
  • One process, and one Virtual machine for each application.
  • One process common for all applications, and one Virtual machine for each application.
  • One process common for all applications, and one Virtual machine common for each application.

Answer: B One process, and one Virtual machine for each application.
Description: Default android will give One process, and one Virtual machine for each application.

14

Does android applications leak memory? Is there any possibility?

  • android is based on java, java has garbage collector to collect unused memory, so don't need to worry about memory leaks.
  • Java GC doesn't guarantee about memory leaks, if it finds any memory pointed by some one by mistake, then it might not clean that memory.
  • option 2 is true, there may be some situations where activity will be pointed by some ui controls, which will be pointed by some static variables, which leads to memory leak in android.
  • all of the above optoins are true.

Answer: C option 2 is true, there may be some situations where activity will be pointed by some ui controls, which will be pointed by some static variables, which leads to memory leak in android.
Description: Java GC(Garbage Collector) doesn't guarantee about memory leaks, if it finds any memory pointed by some one, then java will assume that the memory is under use. In that case it will not clean that memory.there may be some situations where activity (this pointer) will be pointed by some UI controls, which will be pointed by some static variables, which leads to memory leak in android.
Note : Java doesn't guarantee about memory leaks. It is the programmers responsibility to use static variables and contexts properly. Else it may lead to serious memory leaks in android.

15

Can a static variable point to an instance variable which is pointing to an activity context?

  • No, it might lead to dangerous memory leaks.
  • No, because it is an infinite loop.
  • Yes, any one can point to any thing as long as both are part of same application.
  • option 3 is true, because only other apps can't access different process's properties.

Answer: A No, it might lead to dangerous memory leaks.
Description: Having link between static variables and UI controls which points to "this" pointer (activity context), may lead to serious memory leaks. Try avoid these kind of links.

16

What is the android compilation and execution process/ cycle?

  • test.java -> compile -> test.class -> dvm -> final machine code
  • test.java -> compile -> test.class -> dx tool -> .dex -> dvm -> final machine code
  • test.java -> compile -> test.class -> .dex -> dvm -> final machine code
  • test.java -> compile -> byte code -> interpreter -> test.class -> dx tool -> .dex -> dvm -> final machine code

Answer: B test.java -> compile -> test.class -> dx tool -> .dex -> dvm -> final machine code
Description: .java file -- will be given to -- java compiler -- to generate -- .class file.
all .class files -- will be given to -- dx tool -- to generate single -- dex file
dex file -- will be given to -- dvm -- to generate -- final machine code.
final machine code -- will be given to -- CPU -- to execute.

17

What is anonymous class?

  • Class for which we can't create any object
  • Class for which we can create only one object
  • Class with out any body
  • class with out a class name but with body.

Answer: D class with out a class name but with body.
Description: Anonymous classes are those for which there is no class name, but body will exist. You can create anonymous classes by extending a base class or by implementing an interface. Eg: for anonymous class is button click listeners in Android.

18

What is a singleton class?

  • Class which can't be extended, means only one definition for that class will be there.
  • Class for which we can create only one object
  • Class for which we can't create any object
  • Class which has only one base class.

Answer: B Class for which we can create only one object
Description: It is a design pattern, where a class is designed in such a way that, there is only object for that class. This can be achieved in many ways, general way of implementation is by making the constructor as private, and creating and returning object through a static method of that class.

19

What is the life cycle of and android application process?

  • (application)Process will be loaded into memory before loading first component of the application, and will be killed after destroying all components.
  • (application)Process will be loaded into memory after loading first component of the application, and will be killed after destroying all components.
  • (application)Process will be loaded into memory before loading first component of the application, and will be always staying in the memory.
  • (application)Process will be loaded into memory before loading first component of the application, and will be killed after destroying all components.But if user is visiting that application very frequently, then android might not kill the process at all to optimize the loading time of that application.

Answer: D (application)Process will be loaded into memory before loading first component of the application, and will be killed after destroying all components.But if user is visiting that application very frequently, then android might not kill the process at all to optimize the loading time of that application.
Description: If user is visiting an application very frequently, then its better to retain that application in the memory rather than killing it. Reason for this is, next time when user visits the same application no need to load that application into memory, as it is already in memory. So user will feel happy for showing application very quickly. This is called as empty process(application).

20

How serializable differ from parcel?

  • Parcels are used in Binders. We use parcels for only IPCs, for normal serialization we use serializables.
  • Parcels are used in Binders. We can use and also suggestible to use parcels for any kind of serialization use cases.
  • Binders are used in Parcels. We use Serializables for only IPCs, for normal serialization we use parcels.
  • Both are same, you can use any of them in any serialization scenarios.

Answer: A Parcels are used in Binders. We use parcels for only IPCs, for normal serialization we use serializables.
Description: Parcel is not a general-purpose serialization mechanism.This class is designed as a high-performance IPC transport. used heavily in IBinders. for normal serialization concepts, use Serializables. since serializables are heavy and takes time, we use Parcels for IPC in embedded devices.