Close or hide the Android Soft Keyboard from code


Are you trying to  make close or hide the Soft Keyboard in your app using code. here is the solution .

Force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field.

EditText myEditText = (EditText) findViewById(R.id.myEditText);  
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm
.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);


This will force the keyboard to be hidden in all situations. In some cases you will want to pass in InputMethodManager.HIDE_IMPLICIT_ONLY as the second parameter to ensure you only hide the keyboard when the user didn't explicitly force it to appear (by holding down menu).

Happy Codting

Validate email in JavaScript?


This is one of those useful things that people will be Googling for validate email address on Javascript, this tutorial mostly used when you are developing app on Cross platform, like sencha, phonegap.

function validateEmail(email) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);

}

Here, Using regular expressions is probably the best way. Here's an example (live demo):


Happy Coding!!!

Java Tutorials: Calculate fibonacci series in Java


Calculating fibonacci series in Java

public class Example1 {

public static void main(String [] args) {
 fibonacciLoop(5);
}

 public static void fibonacciLoop(int n){
      if (n == 0) {
           System.out.println("0");
       } else if (n == 1) {
           System.out.println("0, 1, ");
       } else {
           System.out.print("0, 1,  ");
           int a = 0;
           int b = 1;
           for (int i = 1; i < n; i++) {
               int nextNumber = a + b;
               System.out.print(nextNumber + ", ");
               a = b;
               b = nextNumber;
           }
       }
    }

Output:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55,


ebook: Migrating to Android for iOS Developers


Migrating to Android for iOS Developers gives you - as an experienced iOS app developer - the ability to learn native Android apps development from scratch. Through case studies and examples, this book starts with a simple but meaningful Hello Android project. Then, this book continues by providing guidelines and tutorial projects showing you how to translate iOS apps to Android right from the beginning.

What you’ll learn

• How to maximize your existing iOS mobile knowledge to learn Android programming skills
• How to use the Android integrated development environment with the Eclipse ADT plugin
• How to translate your existing iOS code to Android with the following common mobile topics:
° Common mobile screen navigation patterns
° User interface components and UI animations
° Storing data
° Networking and using remote services
° Using system apps
° Maps and location awareness
° Mobile search frameworks
° Mobile analytics


  • SBN13: 978-1-484200-11-7
  • 532 Pages
  • User Level: Beginner to Intermediate
  • Publication Date: July 20, 2014 

  • What are the differences between git pull and git fetch?

    When you are getting confuse in git pull and git fetch, here is the some solutions, may be helpful.

    In the simplest terms, git pull does a git fetch followed by a git merge.
    You can do a git fetch at any time to update your remote-tracking branches under refs/remotes/<remote>/. This operation never changes any of your own local branches under refs/heads, and is safe to do without changing your working copy. I have even heard of people running git fetch periodically in a cron job in the background (although I wouldn't recommend doing this).


    A git pull is what you would do to bring a local branch up-to-date with its remote version, while also updating your other remote-tracking branches.

    or

    • When you use pull, Git tries to automatically do your work for you. It is context sensitive, so Git will merge any pulled commits into the branch you are currently working in. pull automatically merges the commits without letting you review them first. If you don’t closely manage your branches you may run into frequent conflicts.
    • When you fetch, Git gathers any commits from the target branch that do not exist in your current branch and stores them in your local repository. However, it does not merge them with your current branch. This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files. To integrate the commits into your master branch, you use merge.

    How to make app using phonegap in eclipse

    If you succesfully installed android SDK bundles, then create simple android project then follows the instruction:

    Add the PhoneGap library

    You now have a simple Android application. Before you can write a PhoneGap application, you need to add the PhoneGap library. There are two files: a JavaScript file that contains the PhoneGap API called by our application, and a native JAR file containing the native implementation for the PhoneGap API.
    1. Expand the AndroidPhoneGap project tree view, as shown in Figure 10:
      Figure 10. Android project with PhoneGap library
      Android project with PhoneGap library
    2. Create the directory \assets\www. Also create the directory \libs if it doesn't already exist.
    3. Unzip the PhoneGap download and locate the Android subdirectory.
    4. Copy the three PhoneGap library files for Android to the following Eclipse project folders:
      • Copy phonegap-1.0.0.jar to \libs\phonegap-1.0.0.jar
      • Copy phonegap-1.0.0.js to \assets\www\phonegap-1.0.0.js
      • Copy xml/plugins.xml to \res\xml\plugins.xml
    Even though the PhoneGap JAR file is copied into the project, you also need to add it to the project's build path.
    1. Select Project > Properties > Java Build Path > Libraries > Add JARs….
    2. Add phonegap-1.0.0.jar by navigating to it in the project, as shown in Figure 11:
    Figure 11. Adding PhoneGap JAR
    Adding PhoneGap JAR
    The final step in preparing the example Android application to use PhoneGap is to modify App.java. Because a PhoneGap application is written in HTML and JavaScript, you need to change App.java to load your HTML file using loadUrl(), as shown in Listing 2. You can edit App.java by double-clicking on App.java in the tree view shown in Figure 10.
    Listing 2. App.java
    Package com.ibm.swgs;
    import android.os.Bundle;
    import com.phonegap.*;
    public class App extends DroidGap //Activity
    {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
    super.loadUrl("file:///android_asset/www/index.html");
    }
    }

    Write the PhoneGap application

    You're now ready to start writing the PhoneGap application. For Android, files under the asset directory are referenced using file:///android_asset. As specified in loadUrl() in Listing 2, you need to create an index.html file under assets/www.
    After creating index.hml, enter the contents of Listing 3 below.
    Listing 3. index.html
    <!DOCTYPE HTML>
    <html>
    <head>
    <title>PhoneGap</title>
    <script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
    </head>
    <body onload='document.addEventListener("deviceready", deviceInfo, false);'>
    <script>
    function deviceInfo() {
    document.write("<h1>This is Phonegap 1.0.0 running on "+device.platform+"
    "+device.version+"!</h1>");
    }
    </script>
    </body>
    </html>
    A brief explanation of index.html is in order. Before calling any PhoneGap APIs, we must wait for the deviceready event, which indicates that the native portion of PhoneGap has been initialized and is ready. In Listing 3, the onload callback registers for deviceready. When it fires, we write out the device's OS and version.
    Since PhoneGap uses native features that are protected by permissions, you need to modify AndroidManifest.xml to include these uses-permission tags. You also need to specify the support-screens tag, the android:configChanges property, and the com.phonegap.DroidGap activity tag, as shown in Listing 4:
    Listing 4. AndroidManifest.xml
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ibm.swgs"
    android:versionCode="1"
    android:versionName="1.0">
    <supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:resizeable="true"
    android:anyDensity="true"
    />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".App"
    android:label="@string/app_name"
    android:configChanges="orientation|keyboardHidden">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    <activity android:name="com.phonegap.DroidGap" android:label="@string/app_name"
    android:configChanges="orientation|keyboardHidden">
    <intent-filter>
    </intent-filter>
    </activity>
    </application>
    </manifest>

    Run the application in the Android emulator

    The PhoneGap application is now ready to run. Select Run > Run As > Android Application, and you should see something similar to Figure 12
    Figure 12. Android emulator
    Screenshot of Android emulator and message 'This is PhoneGap 1.0.0 running on Android 2.2!'
    Eclipse automatically builds the application, launches the emulator, and installs and runs it on the emulator.
    The emulator can take several minutes to start up. To speed development, keep the emulator running until you are done with your development session. Eclipse will automatically use a running emulator instead of launching a new one.

    Get products and technologies

    Source:IBM

    Common android developer interview question and anwers

    Here is common interview asked during interview .

    What is Android?
    #  It is an open-sourced operating system that is used primarily on mobile devices, such as cell phones and tablets.
    It is a Linux kernel-based system that’s been equipped with rich components that allows developers to create and run apps that can perform both basic and advanced functions.

    Explain in brief about the important file and folder when you create new android application.

    # When you create android application the following folders are created in the package explorer in eclipse which are as follows:

    src: Contains the .java source files for your project. You write the code for your application in this file. This file is available under the package name for your project.

    gen —This folder contains the R.java file. It is compiler-generated file that references all the resources found in your project. You should not modify this file.

    Android 4.0 library: This folder contains android.jar file, which contains all the class libraries needed for an Android application.

    assets: This folder contains all the information about HTML file, text files, databases, etc.

    bin: It contains the .apk file (Android Package) that is generated by the ADT during the build process. An .apk file is the application binary file. It contains everything needed to run an Android application.

    res: This folder contains all the resource file that is used byandroid application. It contains subfolders as: drawable, menu, layout, and values etc.

    What is an Activity?
    # A single screen in an application, with supporting Java code.

    What is an Intent?
    # A class (Intent) which describes what a caller desires to do. The caller will send this intent to Android’s intent resolver, which finds the most suitable activity for the intent. E.g. opening a PDF document is an intent, and the Adobe Reader apps will be the perfect activity for that intent (class).

    What is the Android Architecture?
    #  Android Architecture is made up of 4 key components:
    - Linux Kernel
    - Libraries
    - Android Framework
    - Android Applications


    How do you handle multiple resolution screens in android?

    # The following five properties help you to achieve multiple resolution screens in android:

        Screen size – Screen sizes are divided into four generalized sizes: small, normal, large, and extra-large.
        Screen density – Screen densities are also divided into four generalized densities: low, medium, high, and extra-high.
        Orientation – When user rotates the device the orientation of the device also gets changed.
        Resolution – The total number of physical pixels on a screen.
        Density – independent pixel (dp) – Provides you a density-independent way to define your layouts.

    What is a resource?
    # A user defined JSON, XML, bitmap, or other file, injected into the application build process, which can later be loaded from code


     What is an Explicit Intent?
    #
    - Explicit intent specifies the particular activity that should respond to the intent.
    - They are used for application internal messages.

     What is an Implicit Intent?
    #
    - In case of Implicit Intent, an intent is just declared.
    - It is for the platform to find an activity that can respond to it.
    - Since the target component is not declared, it is used for activating components of other applications.


    What is the role of Orientation?

    # Orientation is used to determine the presentation of LinearLayout. It may be presented in rows or columns.


    What is adb?
    #  Adb is short for Android Debug Bridge. It allows developers the power to execute remote shell commands. Its basic function is to allow and control communication towards and from the emulator port.


    What is Dalvik Virtual Machine?
    #
    - It is Android's virtual machine.
    - It is an interpreter-only virtual machine which executes files in Dalvik Executable (.dex) format. This format is optimized for efficient storage and memory-mappable execution.

    What are the different states wherein a process is based?
    #  There are 4 possible states:
    - foreground activity
    - visible activity
    - background activity
    - empty process

    What is the APK format?
    # The APK file is compressed AndroidManifest.xml file with extension .apk. It also includes the application code (.dex files), resource files, and other files which are compressed into a single .apk file.

    What is the AndroidManifest.xml?
    # This file is essential in every application. It is declared in the root directory and contains information about the application that the Android system must know before the codes can be executed.

    What is a Fragment?
    # A fragment is a part or portion of an activity. It is modular in a sense that you can move around or combine with other fragments in a single activity. Fragments are also reusable.

    Describe Briefly the Android Application Architecture
    # Android Application Architecture has the following components:

        Services like Network Operation
        Intent – To perform inter-communication between activities or services
        Resource Externalization – such as strings and graphics
        Notification signaling users – light, sound, icon, notification, dialog etc.
        Content Providers – They share data between applications

    How make weblink(hyperlink) in textview in android

    Weblink or Hyperlink in textview, simple way to make it:

    Textview tv_link= (Textview)findViewById(R.id.tvLink);
    tv_link.setText("prandroid@gmail.com");
    Linkify.addLinks(tv_link, Linkify.ALL);

    or may be use this also:

    TextView tvLinkTest= (TextView) findViewById(R.id.tl);
    tvLinkTest.setMovementMethod(LinkMovementMethod.getInstance());

    next alternative method is:

    <TextView
    android:text="www.hello.com"
    android:id="@+id/TextView01"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:autoLink="web">
    </TextView>

    Happy Coding!!!

    Display Second Largest number in java

    Displaying second largest number in string array in java.

    Here is the full source code, how to display second largest number in integer array ,
    public class One {
    public static void main(String[] args) {

            int arr[] = {5,8,0,7,12};
         
            System.out.println("SortedSet = second largest number is--->"+displaySecond(arr));
           
    }

    private static int displaySecond(int[] arr1) {
    if (arr1.length==0 || arr1.length==1) {
            return -1;
            }else {
            SortedSet<Integer> set = new TreeSet<Integer>();
            for (int i: arr1) {
                set.add(i);
            }
            // Remove the maximum value; print the largest remaining item
            set.remove(set.last());
            return set.last();
    }
    }
    }

    Output looks like:

    SortedSet = second--->8

    Happy Coding!!!


    Press back and Exit app in androird


    If you getting trouble when pressing back don't exit app, then this article will help you. Here first time your will display toast message, please press again for exit app.

    here is the full source code:

    public class MainActivity extends Activity {
    private static long back_pressed;
    private Toast toast;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    }

    @Override
    public void onBackPressed() {

    if (back_pressed + 2000 > System.currentTimeMillis()){
    // need to cancel the toast here
    toast.cancel();
    // code for exit
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    }else{
    toast = Toast.makeText(getBaseContext(), "Please click BACK again to exit", Toast.LENGTH_SHORT);
    toast.show();
    }
    back_pressed = System.currentTimeMillis();
    }

    Output looks like:



    Happ Coding!!
    }

    Refresh activity on back button in android


    Normally, when user click the back button in android, the next view is not refreshed. I had this problem when I was doing the settings. if user changed the some settings and hit back button, the new settings won’t be applied to the “back” list view since all the cells are reused.
    you can do some scroll to refresh the list view but that is definitely not something we wanna user to do.
    first solution is to override the onResume method in the back view, but it is not guaranteed to work in listView.
    However the following code should do the work:

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && isNightModeToggled) {
            Intent a = new Intent(this,MainActivity.class);
            a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(a);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    Happy Coding!!!!

    Programmatically Displaying the Settings of device


    Sometimes, you want to set wifi, bluetooth and others setting then from programmatically do things here in your code

    you can use the startActivity()
    method together with an Intent object. The following shows some examples:

        //---display the main Settings page---
        startActivity(
            new Intent(Settings.ACTION_SETTINGS));
           
        //---display the Location access settings page---
        startActivity(new Intent(
            Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                   
        //---display the Wireless & networks settings page---
        startActivity(new Intent(
            Settings.ACTION_AIRPLANE_MODE_SETTINGS));
           
        //---display the Bluetooth settings page---
        startActivity(new Intent(
            Settings.ACTION_BLUETOOTH_SETTINGS));
           
    Output Looks Like:

            In general, you use the predefined constant Settings.ACTION__SETTINGS.
    The full list can be found here: http://developer.android.com/reference/android/provider/Settings.html

    Happy Coding!!!

    Job: Software Engineer – Mobile in UK


    Job Description

    This role will be involved in the development, deployment, maintenance and testing components of the DECIDE programme, primarily “App Lab”, a private App Store that will provide a large scale testing environment to support start-up and other companies with private trialling of their applications. The role will also include helping design, prototype and run mobile app deployment, as well as helping develop the best practice policy and guideline documents for development, testing and deployment.

    Skills & Requirements

    You must be a skilful, hard working and innovative engineer, with highly developed technical skills and able to effective communicate with and work within a team. Good at problem solving, and analytical thinking. You must be able to demonstrate excellent organisational and interpersonal skills, the ability to take on responsibility and exercise skills in time management. Specifically you need to be able to demonstrate the experience and competencies mentioned in the job description.
    A full job description can be found here (Ref:1428357).

    About UCL

    UCL Advances, UCL’s centre for entrepreneurship, has been formed to develop new links between UCL and businesses of all kinds, with a particular focus on entrepreneurs and small and medium–sized enterprises.
    DECIDE helps London’s entrepreneurs test, iterate and launch ideas. Part of Advances, UCL’s Centre for Entrepreneurship, we work with startups and leading companies to transform and validate ideas through early stage product development and pre-commercial testing. We offer 3 core services; UX Lab, a user experience evaluation and design service, Device Lab, London’s largest open device library, and App Lab, a private app store for in-the-wild user testing on UCL’s community of 35,000 people.
    DECIDE is a diverse and ambitious programme, with App Lab currently being one of the most interesting open innovation projects in the country, making this a unique opportunity. The successful candidate will be joining a dynamic, highly motivated, fun and entrepreneurial team – described as fantastically strange by one of our inters!

    How to apply

    We ideally want someone these posts to be filled and for the candidates to start as soon as possible, there are therefore two options when applying:
    1) Apply for the post full time, the job will be advertised until the 27th of August, interviews will take place in September and the job will start soon after that depending on notice the period. To apply please click on the "apply" link on this page.
    2) Apply for the contractor/temporary role which will be filled as soon as we find a suitable candidate and will continue until the full time position is filled – this candidate will equally be welcome to fill in an application for the full time role. To apply using the application form please email c dot newman at ucl dot ac dot uk

    Source: http://careers.stackoverflow.com/jobs/65075/software-engineer-mobile-ucl?a=5hHAxcPQ2I&searchTerm=android

    How to create Custom Notification in Android


    Customization notification part needed sometimes, that you modified android notification of user request. Here is the sample code for custom notification:

    Main.Java code :

    public class NotificationToastActivity extends Activity {
    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
         
    Button button = (Button) findViewById(R.id.toast_button);
    button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
         
           Toast toast = new Toast(getApplicationContext());

           toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
           toast.setDuration(Toast.LENGTH_LONG);
         
           toast.setView(getLayoutInflater().inflate(R.layout.custom_toast,null));

           toast.show();
    }
    });

        }
    }

    main.xml code:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <Button
            android:id="@+id/toast_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="Show Toast"
            android:textSize="24sp" />

    </RelativeLayout>

    and final custom_layout.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#0000FF"
        android:orientation="horizontal"
        android:padding="10dp" >

        <ImageView
            android:id="@+id/custom_image"
            android:layout_width="44dp"
            android:layout_height="44dp"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:src="@drawable/custom_image" />

        <TextView
            android:id="@+id/customtext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@id/custom_image"
            android:text="Display, Custom Toast Here"
            android:textColor="#fff"
            android:textSize="15sp" />

    </RelativeLayout>

    Here is the some snapshots:




    Happy Coding!!!

    Create custom button in Android using XML


    How to create custom button in android using xml style file . which is placed on drawable folder .

    Now, just create shape of the ImageButton to have black shader background.
    android:background="@drawable/button_shape"
    and the button_shape is the xml file in drawable resource:

        <?xml version="1.0" encoding="UTF-8"?>
    <shape
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
    android:width="1dp"
    android:color="#505050"/>
    <corners
    android:radius="7dp" />

    <padding
    android:left="1dp"
    android:right="1dp"
    android:top="1dp"
    android:bottom="1dp"/>

    <solid android:color="#505050"/>

    </shape>

    Happy Coding!!!

    Differences and Similarities Between Android and iOS.


    Diffen.com, summarize between  differences and similarities Google's Android and Apple's iOS.

    Differences:



    Android


    iOS


    Company/Developer Google Apple Inc.
    OS family Linux OS X, UNIX
    Customizability A lot. Can change almost anything. Limited unless jailbroken
    Initial release September 23, 2008 July 29, 2007
    Programmed in C, C++, java C, C++, Objective-C
    Dependent on a PC or a Mac No No
    Easy media transfer depends on model with desktop application
    Source model Open source Closed, with open source components.
    Open source Kernel, UI, and some standard apps The iOS kernel is not open source but is based on the open-source Darwin OS.
    Widgets Yes No, except in NotificationCenter
    Call features supported Auto-respond Auto-respond, call-back reminder, do not disturb mode
    Internet browsing Google Chrome (or Android Browser on older versions; other browsers are available) Mobile Safari (Other browsers are available)
    Available on Many phones and tablets, including
    Kindle
    Fire(modified android), LG, HTC,
    Samsung
    , Sony, Motorola, Nexus, and others.
    iPod Touch, iPhone, iPad, Apple TV (2nd and 3rd generation)
    Interface Touch screen, Smartwatch Touch screen
    Messaging Google Hangouts iMessage
    Voice commands Google Now (on newer versions) Siri
    Maps Google Maps Apple Maps
    Video chat Google Hangouts Facetime
    App store Google Play – 1,000,000+ Apps. Other app stores like
    Amazon
    and Getjar also distribute Android apps. (unconfirmed ".APK's")
    Apple app store – 1,000,000+ Apps
    Market share 81% of smartphones, 3.7% of tablets in North America (as of Jan'13) and 44.4% of tablets in Japan (as of Jan'13). In the United States in Q1 2013 - 52.3% phones, 47.7% tablets. 12.9% of smartphones, 87% of tablets in North America (as of Jan'13) and 40.1% of tablets in Japan (as of Jan'13)
    Available language(s) 32 Languages 34 Languages
    Latest stable release Android 4.4 Kitkat (October, 2013) 7.1 (March 10, 2014)
    Device manufacturer Google, LG, Samsung, HTC, Sony, ASUS, Motorola, and many more Apple Inc
    Upcoming releases/Release dates Unknown Unknown
    Working state Current Current
    Website android.com apple.com


    Similarities 



    Android


    iOS


    Dependent on a PC or a Mac No No
    Upcoming releases/Release dates Unknown Unknown
    Working state Current Current

    What is Context in Android?


    Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc. More: http://developer.android.com/reference/android/content/Context.html

    and simple answer on stackoverflow gives by Sameer Segal.
    As the name suggests, its the context of current state of the application/object. It lets newly created objects understand what has been going on. Typically you call it to get information regarding another part of your program (activity, package/application)
    You can get the context by invoking getApplicationContext(), getContext(), getBaseContext() or this (when in the activity class).
    Typical uses of context:

    • Creating New objects: Creating new views, adapters, listeners:
      TextView tv = new TextView(getContext());
      ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);
    • Accessing Standard Common Resources: Services like LAYOUT_INFLATER_SERVICE, SharedPreferences:
      context.getSystemService(LAYOUT_INFLATER_SERVICE)   
      getApplicationContext
      ().getSharedPreferences(*name*, *mode*);
    • Accessing Components Implicitly: Regarding content providers, broadcasts, intent
      getApplicationContext().getContentResolver().query(uri, ...);
    Code Here Code explain on video , Watch on youtube:

    Vogella gives example, you can check the size of the current device display via the Context.
    The Context class also provides access to Android services, e.g., the alarm manager to trigger time based events.
    Activities and services extend the Context class. Therefore they can be directly used to access the Context. More: http://www.vogella.com/tutorials/Android/article.html

    Happy Coding!!!                                

    Android error: Failed to install *.apk on device *: timeout


    Do most important this, when your faced this problem, lets hope you have to through away this problem.

    Try changing the ADB connection timeout. I think it defaults that to 5000ms and I changed mine to 10000ms to get rid of that problem.
    If you are in Eclipse, you can do this by going through

    Window-> Preferences -> Android -> DDMS -> ADB Connection Timeout (ms)

    Sometime, it works by doing this also:
    don't use USB 3.0 ports for connection beetwen PC and Android phone!
    USB 3.0 - Port with blue tongue
    USB 2.0 - Port with black tongue

    Happy coding!!!

    Jar Mismatch Found 2 versions of android-support-v4.jar in the dependency list



    Step #1: Undo all that. If you are messing with the build path, on R16 or higher version of the ADT plugin for Eclipse, you're doing it wrong.
    Step #2: Pick one of those two versions of the JAR, or pick the one from the "extras" area of your SDK installation.
    Step #3: Put the right JAR in App Library.
    Step #4: Delete the one from App Free, since it will pick up that JAR from App Library.
    You are welcome to instead have the same actual JAR file in both spots (App Free and App Library), though that just takes up extra space for no reason.
    This wrote CommonsWare.
    may work some time for this:
    Delete android-support-v4.jar from library and project. Then go in <sdk>/extras/android/support/samples/Support4Demos/ and copy android-support-v4.jarand paste in libs folder of both.

    and finally all of not working, then try this:
    1. Delete android-support-v4.jar from App Free
    2. Add the same file from App Library to App Free