Excerpt for Android Development Interview Questions You'll Most Likely Be Asked by Vibrant Publishers, available in its entirety at Smashwords

Android Development

Interview Questions


You'll Most Likely Be Asked


Job Interview Questions Series


www.vibrantpublishers.com


*****



Android Development Interview Questions You'll Most Likely Be Asked

Published by Vibrant Publishers at Smashwords

Copyright 2012 Vibrant Publishers, USA.

Smashwords Edition, License Notes

This ebook is licensed for your personal use only. This ebook may not be re-sold or given away to other people. If you would like to share this book with another person, please purchase an additional copy for each recipient. If you’re reading this book and did not purchase it, or it was not purchased for your use only, then please return to Smashwords.com and purchase your own copy. Thank you for respecting the hard work of this author.


This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. The author has made every effort in the preparation of this book to ensure the accuracy of the information. However, information in this book is sold without warranty either expressed or implied. The Author or the Publisher will not be liable for any damages caused or alleged to be caused either directly or indirectly by this book.


Vibrant Publishers books are available at special quantity discount for sales promotions, or for use in corporate training programs. For more information please write to bulkorders@vibrantpublishers.com


Please email feedback / corrections (technical, grammatical or spelling) to spellerrors@vibrantpublishers.com


To access the complete catalogue of Vibrant Publishers, visit www.vibrantpublishers.com


*****



Table of Contents

1. Activities

2. Services

3. Content Provider

4. Intents

5. Processes and Threads

6. User Interface

7. Notifications

8. Styles and Themes

9. Binding to Data with AdapterView

10. Common Layout Objects

11. Resources

12. Data Storage

13. Data Backup

14. Security and Permissions

15. AndroidManifest

16. Graphics

17. Hardware Acceleration

18. OpenGL

19. Testing

20. RenderScript

HR Questions

INDEX


*****




Android Development Interview Questions


Review these typical interview questions and think about how you would answer them. Read the answers listed; you will find best possible answers along with strategies and suggestions.


*****



Activities


1: How to declare an activity in the manifest?

Answer:

In order to declare your activity, open your manifest file and add an <activity> element as a child of the <application> element. For example::

<manifest ... >

<application ... >

<activity android:name=".ExampleActivity" />

...

</application ... >

...

</manifest >


2: How can an activity include intent filters?

Answer:

An activity can include intent filter like this:

<activity android:name=".ExampleActivity" android:icon="@drawable/app_icon">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>


3: How to start an activity?

Answer:

Activity can be started as:

Intent intent = new Intent(this, SignInActivity.class);

startActivity(intent);


4: How can a user send an email message with the intent? Explain with an example.

Answer:

Example is as under:

Intent intent = new Intent(Intent.ACTION_SEND);

intent.putExtra(Intent.EXTRA_EMAIL, recipientArray);

startActivity(intent);


5: How to start an activity for a result?

Answer:

Sometimes we need to start an activity for a result. An example is given below:

private void pickContact() {

// Create an intent to "pick" a contact, as defined by the content provider URI

Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);

startActivityForResult(intent, PICK_CONTACT_REQUEST);

}


@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

// If the request went well (OK) and the request was PICK_CONTACT_REQUEST

if (resultCode == Activity.RESULT_OK && requestCode == PICK_CONTACT_REQUEST) {

// Perform a query to the contact's content provider for the contact's name

Cursor cursor = getContentResolver().query(data.getData(),

new String[] {Contacts.DISPLAY_NAME}, null, null, null);

if (cursor.moveToFirst()) { // True if the cursor is not empty

int columnIndex = cursor.getColumnIndex(Contacts.DISPLAY_NAME);

String name = cursor.getString(columnIndex);

// Do something with the selected contact's name...

}

}

}


6: How to shut Down an Activity?

Answer:

There can be two different ways to do so. By calling its finish() method and also by finishActivity().


7: In how many different states can an activity exist?

Answer:

There are three different states in which an activity can exist. Resumed, Paused and Stopped.


8: How to implement the lifecycle callbacks?

Answer:

Lifecycle callbacks can be implemented as:

public class ExampleActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// The activity is being created.

}

@Override

protected void onStart() {

super.onStart();

// The activity is about to become visible.

}

@Override

protected void onResume() {

super.onResume();

// The activity has become visible (it is now "resumed").

}

@Override

protected void onPause() {

super.onPause();

// Another activity is taking focus (this activity is about to be "paused").

}

@Override

protected void onStop() {

super.onStop();

// The activity is no longer visible (it is now "stopped")

}

@Override

protected void onDestroy() {

super.onDestroy();

// The activity is about to be destroyed.

}

}


9: When does entire lifetime of an activity happen?

Answer:

It happens between the call to onCreate() and the call to onDestroy().


10: When does visible lifetime of an activity happen?

Answer:

It happens between the call to onStart() and the call to onStop().


11: When does foreground lifetime of an activity happen?

Answer:

It happens between the call to onResume() and the call to onPause().


12: What is a Fragment?

Answer:

The fragment can be best explained as a behavior or a portion of user interface in an Activity.


13: Give an example of a fragment.

Answer:

Example is as under:

public static class ExampleFragment extends Fragment {

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

// Inflate the layout for this fragment

return inflater.inflate(R.layout.example_fragment, container, false);

}

}


14: How to add a fragment to an activity?

Answer:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="horizontal"

android:layout_width="match_parent"

android:layout_height="match_parent">

<fragment android:name="com.example.news.ArticleListFragment"

android:id="@+id/list"

android:layout_weight="1"

android:layout_width="0dp"

android:layout_height="match_parent" />

<fragment android:name="com.example.news.ArticleReaderFragment"

android:id="@+id/viewer"

android:layout_weight="2"

android:layout_width="0dp"

android:layout_height="match_parent" />

</LinearLayout>


15: How one can acquire an instance of FragmentTransaction from the FragmentManager?

Answer:

An example to acquire an instance of FragmentTransaction is given below:

FragmentManager fragmentManager = getFragmentManager();

FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();


16: How to create new fragment and transaction?

Answer:

Do the following:

Fragment newFragment = new ExampleFragment();

FragmentTransaction transaction = getFragmentManager().beginTransaction();


17: How to add a transaction to the back stack?

Answer:

The following code snippet shows how to add a transaction to the back stack:


Purchase this book or download sample versions for your ebook reader.
(Pages 1-9 show above.)