Skip to main content

Android Interview Question for Freshers

I) What are the components of Android?
The main components of Android are:
1) Activity
Activity provides an interface for users to interact with the application and take an action (for instance: Login to a website). The different screens/windows of an application are the different activities. An application generally has multiple activities.
Activities are like the pages in a website.
2) Intent
Think of Intent as a message to allow the application to request action from the other application components (like activity), for instance VIEW, CALL, PLAY etc.
3) Service


Services are components that do not have a User Interface; they run in the background. They would continue to run, even if you switch to another activity or application.
4) Broadcast receiver
A Broadcast receiver comes into action only in specific situations. Suppose an Intent for which a particular broadcast receiver has been registered occurs, the broadcast receiver is triggered into action and the user gets a notification for the same.
5) Content Provider
Content provider is a data store that enables data sharing across different applications. Content providers provide a uniform interface to access the data. An example is Call logs.

1. When does onResume() method called?

onResume() method is an activity lifecycle method. This is called when the activity come to foreground. You can override this method in your activity to execute code when activity is started, restarted or comes to foreground.

2. How to launch an activity in your application?

For launching an activity, we need to create an explicit intent that defines the activity that we wish to start. In the below code snippet, the first parameter to Intent constructor is the current activity context and the second parameter is your new activity class.startActivity() method can be called on Activity context.
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
If you want to start an activity from fragment
Intent intent = new Intent(getActivity(), SecondActivity.class);
getActivity().startActivity(intent);

3. How to define an Activity as launcher activity in application Manifest file?

All the activities used in the application should be defined in application manifest file. For launcher activity you need to define intent filter as shown in the below code snippets.
<activity android:name=".MyActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

4. What is a ANR ?

ANR is short for Application Not Responding. Android systems shows this dialog, if application is performing too much of task on main thread and been unresponsive for a long period of time.

5. What are the measures to avoid application ANR?

ANR in application is annoying to user. It can be caused due to various reasons. Below are some of the tips to avoid ANR
·         Perform all you long running network or database operation in separate thread
·         If you have too much of background tasks, then take it off the UI thread. You may use IntentService
·         Server not responding for longer period can be guilt for ANR. To avoid always define HTTP time out for your all your webs service calls.
·         Be watchful of infinite loops during your complex calculations

6. What is the difference between a regular .png and a nine-patch image?

The nine patch images are extension with .9.png. Nine-patch image allows resizing that can be used as background or other image size requirements for the target device. The Nine-patch refers to the way you can resize the image: 4 corners that are unscaled, 4 edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.

7. How to share text using android share Intent ?

Share intent is an easy and convenient way of sharing content of your application with other apps.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

8. What is the use of WebView in android?

A WebView is an android UI component that displays webpages. It can either display a remote webpage or can also load static HTML data. This encompasses the functionality of a browser that can be integrated to application. WebView uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, etc.

9. Define different kind of context in android

Context defines the current state of application or object. Context provides access to things such as creating new activity instance, access databases, start a service, etc. You can get the context by invoking getApplicationContext(),getContext(), getBaseContext() or this when in the activity class.
//Creating ui instance
ImageButton button = new ImageButton(getContext());
 
//creating adapter
ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);
 
//querying content provider
getApplicationContext().getContentResolver().query(uri, ...);
 
//start activity. Here this means activity context
Intent intent = new Intent(this, SecondActivity.class);

10. What are the different storage methods in android

Android offers several different options for data persistence.
1.      Shared Preferences – Store private primitive data in key-value pairs. This sometimes gets limited as it offers only key value pairs. You cannot save your own java types.
2.      Internal Storage – Store private data on the device memory
3.      External Storage – Store public data on the shared external storage
4.      SQLite Databases – Store structured data in a private database. You can define many number of tables and can store data like other RDBMS.

Comments

Post a Comment

Popular posts from this blog

Login and Registration Example in JSP with Session

Those who want to start with jsp and MySQL, this is an excellent example for themselves. Here you can learn how to insert data to MySQL using JSP. Also you can learn about session handling in jsp. 1 2 3 4 5 6 7 8 9 10 CREATE TABLE `members` (    `id` int (10) unsigned NOT NULL auto_increment,    `first_name` varchar (45) NOT NULL ,    `last_name` varchar (45) NOT NULL ,    `email` varchar (45) NOT NULL ,    `uname` varchar (45) NOT NULL ,    `pass` varchar (45) NOT NULL ,    `regdate` date NOT NULL ,    PRIMARY KEY   (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; index.jsp 1 2 3 4 5 6 ...

Timer funcitons in JavaScript: Reminder Script

Timers are used in web pages and we will discuss how to setup one and how to use one with an example. The function setTimeout() in function is used and here is its general syntax. mytime = setTimeout(expression, msec); mytime  is the identifier used to identify the current timeout function.  expression  is the statement that is to be executed after the specified time has ticked off.  msec  is the duration of time in milliseconds after which the expression will be executed.  You can see by using setTimeout function we can execute any function or object after a set of time. For example if msec is set 5000 then the expression will be executed after 5 seconds or 5000 milliseconds.  We will try one example where we will have four period buttons and each button will set a different time for another function to execute and display a alert button. We will call it as a reminder script and we will get one alert box based on the period button we click...

Binary Addition

/* File Name : BinAdd.java */    import java.util.*; public class BinAdd    {  public static String addBit(String a, String b, String c)  { String r=""; if(a.equals("1") && b.equals("0") || a.equals("0") && b.equals("1")) { if( c.equals("0")) r="1"; else { r="0"; c="1"; } } else if( a.equals("0") && b.equals("0") ) { if(c.equals("0")) r="0"; else r="1"; } else if( a.equals("1") && b.equals("1") ) { if(c.equals("0")){ r="0"; c="1"; } else { r="1"; c="1"; } } return c+r; }   public static String add(String a, String b)   { String r=""; int len=a.length(); String carry="0"; for(int i=len-1;i...

Real time changing Clock showing date and time

We can display a clock which will be showing the local time of the client computer by using JavaScript. Note that this time displayed is taken from user computer and not from the server.  We have seen in our  date object example how to display current date and time   where the current date and time is displayed once. Here we will try to display changing clock or real time change in date and time by using  setTimeout function . This setTimeout function we have used to trigger the time display function in a refresh rate of 1000 mill seconds ( 1 Sec ). This refresh rate can be changed to any other value. By changing the value to 5000 the clock will refresh and show the exact time once in every 5 seconds.  Here is the demo of this script and code is given below that.  Sat Apr 23 2016 08:27:22 GMT+0530 (IST)   Here is the code <html> <head> <title>(Type a title for your page here)</title> <script type="text/javascript...