Without Book Interview Questions and Answers | Online Test | Moct Test
Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Institute Training Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Android Interview Questions and Answers

Ques 11. How to create/make android apps?

Ans.

We are creating the simple example of android using the Eclipse IDE. For creating the simple example:
1) Create the new android project
2) Write the message (optional)
3) Run the android application

1) For creating the new android project:
Select File > New > Project...
Select the android project and click next
Fill the Details in this diaglog box and click finish
Now an android project have been created. You can explore the android project and see the simple program.
2) For writing the message we are using the TextView class. Change the onCreate method as:
package com.example.helloandroid;  
  
import android.os.Bundle;  
import android.app.Activity;  
import android.view.Menu;  
import android.widget.TextView;  
  
public class MainActivity extends Activity {  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
          
        TextView textview=new TextView(this);  
        textview.setText("Hello Android!");  
          
        setContentView(textview);  
    }  
  
    @Override  
    public boolean onCreateOptionsMenu(Menu menu) {  
        // Inflate the menu; this adds items to the action bar if it is present.  
        getMenuInflater().inflate(R.menu.activity_main, menu);  
        return true;  
    }  
      
}  

3) To run the android application:
Right click on your project > Run As.. > Android Application
The android emulator might take 2 or 3 minutes to boot. So please have patience. After booting the emulator, the eclipse plugin installs the application and launches the activity. You will see something like this:

Is it helpful? Add Comment View Comments
Ques 12. Describe Internal details of previous Hello Android application.
Ans.
Here, we are going to learn the details of first android program.

Android application contains different components such as java source code, string resources, images, manifest file, apk file etc. Let's understand the project structure of android application.

MainActivity.java - Java Source
R.java in generated package - Generated R.java
bin folder - Contains apk file
drawable, activity_main.xml, strings.xml - Resources
AndroidManifest.xml - Manifest

Let's see the java source file created by the Eclipse IDE:
File: MainActivity.java
package com.example.helloandroid;  
  
import android.os.Bundle;  
import android.app.Activity;  
import android.view.Menu;  
import android.widget.TextView;  
  
public class MainActivity extends Activity {//(1)  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {//(2)  
        super.onCreate(savedInstanceState);  
                
        setContentView(R.layout.activity_main);//(3)  
    }  
  
    @Override  
    public boolean onCreateOptionsMenu(Menu menu) {//(4)  
        // Inflate the menu; this adds items to the action bar if it is present.  
        getMenuInflater().inflate(R.menu.activity_main, menu);  
        return true;  
    }  
      

(1) Activity is a java class that creates and default window on the screen where we can place different components such as Button, EditText, TextView, Spinner etc. It is like the Frame of Java AWT.
It provides life cycle methods for activity such as onCreate, onStop, OnResume etc.

(2) The onCreate method is called when Activity class is first created.

(3) The setContentView(R.layout.activity_main) gives information about our layout resource. Here, our layout resources are defined in activity_main.xml file.

File: activity_main.xml
<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context=".MainActivity" >  
  
    <TextView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_centerHorizontal="true"  
        android:layout_centerVertical="true"  
        android:text="@string/hello_world" />  
  
</RelativeLayout>  
As you can see, a textview is created by the framework automatically. But the message for this string is defined in the strings.xml file. The @string/hello_world provides information about the textview message. The value of the attribute hello_world is defined in the strings.xml file.

File: strings.xml
<?xml version="1.0" encoding="utf-8"?>  
<resources>  
  
    <string name="app_name">helloandroid</string>  
    <string name="hello_world">Hello world!</string>  
    <string name="menu_settings">Settings</string>  
  
</resources>  
You can change the value of the hello_world attribute from this file.

Generated R.java file
It is the auto-generated file that contains IDs for all the resources of res directory. It is generated by aapt(Android Asset Packaging Tool). Whenever you create any component on activity_main, a corresponding ID is created in the R.java file which can be used in the Java Source file later.

File: R.java
/* AUTO-GENERATED FILE.  DO NOT MODIFY. 
 * 
 * This class was automatically generated by the 
 * aapt tool from the resource data it found.  It 
 * should not be modified by hand. 
 */  
  
package com.example.helloandroid;  
public final class R {  
    public static final class attr {  
    }  
    public static final class drawable {  
        public static final int ic_launcher=0x7f020000;  
    }  
    public static final class id {  
        public static final int menu_settings=0x7f070000;  
    }  
    public static final class layout {  
        public static final int activity_main=0x7f030000;  
    }  
    public static final class menu {  
        public static final int activity_main=0x7f060000;  
    }  
    public static final class string {  
        public static final int app_name=0x7f040000;  
        public static final int hello_world=0x7f040001;  
        public static final int menu_settings=0x7f040002;  
    }  
    public static final class style {  
        /**  
        Base application theme, dependent on API level. This theme is replaced 
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
     
 
            Theme customizations available in newer API levels can go in 
            res/values-vXX/styles.xml, while customizations related to 
            backward-compatibility can go here. 
         
 
        Base application theme for API 11+. This theme completely replaces 
        AppBaseTheme from res/values/styles.xml on API 11+ devices. 
     
 API 11 theme customizations can go here.  
 
        Base application theme for API 14+. This theme completely replaces 
        AppBaseTheme from BOTH res/values/styles.xml and 
        res/values-v11/styles.xml on API 14+ devices. 
     
 API 14 theme customizations can go here.  
         */  
        public static final int AppBaseTheme=0x7f050000;  
        /**  Application theme.  
 All customizations that are NOT specific to a particular API-level can go here.  
         */  
        public static final int AppTheme=0x7f050001;  
    }  
}  

APK File
An apk file is created by the framework automatically. If you want to run the android application on the mobile, transfer and install it.

Resources
It contains resource files including activity_main, strings, styles etc.

Manifest file
It contains information about package including components such as activities, services, content providers etc.
Is it helpful? Add Comment View Comments
Ques 13. What is Dalvik Virtual Machine for Android?
Ans.
As we know the modern JVM is high performance and provides excellent memory management. But it need to be optimized for low-powered handheld devices.
The Dalvik Virtual Machine (DVM) is optimized for mobile devices. It optimizes the JVM for memory, battery life and performance.
Dalvik is a name of a town in Iceland. The Dalvik VM was written by Dan Bornstein.
The Dex compiler converts the class files into the .dex files that run on the Dalvik VM.
The javac tool compiles the java source file into the class file.
The dx tool takes all the class files of your application and generates a single .dex file. It is a platform-specific tool.
The Android Assets Packaging Tool (aapt) handles the packaging process.
Is it helpful? Add Comment View Comments
Ques 14. What is AndroidManifest.xml file in android?
Ans.
The AndroidManifest.xml file contains information about your package, including components of the application such as activities, services, broadcast receivers, content providers etc.
It performs some other tasks also:
It is responsible to protect the application to access any protected parts by providing the permissions.
It also declares the android api that the application is going to use.
It lists the instrumentation classes. The instumentation classes provides profiling and other informations. These informations are removed just before the application is published etc.
This is the required xml file for all the android application and located inside the root directory.

A simple AndroidManifest.xml file looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"  
    package="com.javatpoint.hello"  
    android:versionCode="1"  
    android:versionName="1.0" >  
  
    <uses-sdk  
        android:minSdkVersion="8"  
        android:targetSdkVersion="15" />  
  
    <application  
        android:icon="@drawable/ic_launcher"  
        android:label="@string/app_name"  
        android:theme="@style/AppTheme" >  
        <activity  
            android:name=".MainActivity"  
            android:label="@string/title_activity_main" >  
            <intent-filter>  
                <action android:name="android.intent.action.MAIN" />  
  
                <category android:name="android.intent.category.LAUNCHER" />  
            </intent-filter>  
        </activity>  
    </application>  
  
</manifest>  

Elements of the AndroidManifest.xml file
The elements used in the above xml file are described below.

<manifest>
manifest is the root element of the AndroidManifest.xml file. It has package attribute that describes the package name of the activity class.

<application>
application is the subelement of the manifest. It includes the namespace declaration. This element contains several subelements that declares the application component such as activity etc.
The commonly used attributes are of this element are icon, label, theme etc.
android:icon represents the icon for all the android application components.
android:label works as the default label for all the application components.
android:theme represents a common theme for all the android activities.

<activity>
activity is the subelement of application and represents an activity that must be defined in the AndroidManifest.xml file. It has many attributes such as label, name, theme, launchMode etc.
android:label represents a label i.e. displayed on the screen.
android:name represents a name for the activity class. It is required attribute.

<intent-filter>
intent-filter is the sub-element of activity that describes the type of intent to which activity, service or broadcast receiver can respond to.

<action>
It adds an action for the intent-filter. The intent-filter must have at least one action element.

<category>
It adds a category name to an intent-filter.
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2017 WithoutBook