Wednesday, April 8, 2015

Google I/O: Android Studio launched to build and test Android apps

Android Studio by Google
Posted by Staff - 27 May 2013
Twitter share icon Facebook share icon Google Plus share icon

This year’s I/O saw Google showcase a series of mobile-related initiatives focused on helping the Android community to grow and prosper.
As Android continues to dominate the smartphone market, expectations are high for new Android activations in 2013. Google are forecasting that in 2013, 900 million Android devices will be activated. The Google Play app now sees more than 2.5 billion installs every month with 48 billion apps downloaded since the launch of the Android Market in late 2008.
From a mobile development perspective, the most important announcement was Google's Android Studio, a series of free tools to create, test and distribute Android apps for a variety of layouts and configurations.
The only prerequisite to use Android Studio is the ability to program in a modern object-oriented language such as Java, C#, C++, VB or anything close to Java at a reasonable level.
While Android Studio is a de facto IDE (Integrated Development Environment), it is currently only available as a Developer Preview and although it can be used there may be some bugs.
To use Android Studio the first thing to do is to install the latest Java JDK, download and install the package from the Android Studio page according to your OS.

Once downloaded, simply click on Start Android Studio and select the New project option and enter a name for the application you want to develop. Follow the required steps and choose an icon for your app and an Activity related to the app then click the Finish button. Android Studio will start creating the application.
When the project has been created, it will be displayed in the Projects tab. Then you only need to concentrate on the files named MainActivity.java which determines the Activity's behavior and Main_Activity.xml which determines the visual appearance of the app.

If you double click on the MainActivity.java file you see the following Java code:
package NAME OF THE APP;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
 
public class MainActivity extends Activity {
@Override
protected void onCreate(
               Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the    
                 action bar if it is present.
 getMenuInflater().inflate(R.menu.main, menu);
 return true;
}
}
The onCreate function is called when your app is run. It creates the view and performs tasks associated with the Activity.
In Main_Activity.xml, using the tree-structure of Android Studio, you can give your app a design and a visual look which reflects the purpose of the App.

Once the App is ready, it's time to test it and this is one of the most important features of Android Studio because it enables you to view how an app will work over different tablets, smartphones and devices. Simply go to Tools-->Android-->AVD Manager to begin testing different AVDs. Each AVD has a different set of characteristics corresponding to different devices.
Once the AVDs have been set up, simply select the device you want from the Android Virtual Devices tab and click Start to run the emulator and see how the application runs on the device(s) you've selected. When Android is ready, simply click the green triangle icon or the menu command Run to get an overview of the app which will appear in the emulator. You can modify and re-run the app without having to restart the AVD or any real hardware connected to the machine.

From a developer's point of view, Android Studio is a good start to dealing with fragmentation as it enables you to see how an Android application runs on different devices and screen sizes. This appears to a first step before Google integrates more services into Android Studio to make developing apps even easier.
(Screenshots courtesy of Karan Balkar & iProgrammer)