Saturday, February 20, 2016

Creating a Simple Example of using TextView, EditText and a Button

In this post, I'm going to start creating a small project by taking a TextView, EditText and a Button.
First up, you need to create the XML Layout for this three widgets to show in the app. Here is the XML code that you need to write in your activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="parthvora.com.myapplication.MainActivity">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Me"
        android:id="@+id/button"
        android:layout_below="@id/editText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:layout_below="@id/button"
        android:layout_marginTop="20dp" />

</RelativeLayout>

This is the basic layout that will show two things EditText to enter the text and Button to click, if you run the application in the Emulator. For configuring the Emulator please visit AVD Setup. This was just the designing portion, for the click of the button to work, we need to jump to the src folder and go to MainActivity.java file and edit it with the following code to make it click and do something when the button gets clicked.

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    EditText name;
    TextView text;
    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        name = (EditText) findViewById(R.id.editText);
        text = (TextView) findViewById(R.id.textView);
        btn = (Button) findViewById(R.id.button);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                text.setText(name.getText());
            }
        });
    }
}

So, this is the code file where we have declared the EditText, TextView and Button. In onCreate method we have initialized them using findViewById method and we have added a setOnClickListener method on the Button that is used to get the click event when user wants to click on the button in your app. Now, on click of the button we want to set the text from EditText and set it in the TextView which will be seen below the button in our app when the user will click on the button. setText is the method using which we can set the text and getText method is used to get the text from the EditText which will be entered by the user.

Tuesday, February 16, 2016

Keeping in Mind the Following Stuff in Android Studio

Take a look at this image. Here you will have to remember some things that will help you to create an Android Application.


 Here you can see there is a flow of files which is located in the app directory, wherein all of the important files are situated. The first of them is the Android Manifest file where all your android app settings are written and added. Also, you can specify Android Permissions and can change your Android Applications name here. Android Permission is the list of all available permission that you want to use in your app from the Android System. Next is the java folder in which all your java source code files will be located. And last is the res folder where all the resource linking to your android app is stored here. In res->layout, all your layouts are stored which are written in XML. In res->values you can add colors.xml for themes and string.xml for common strings that will be used in your app.

Monday, February 15, 2016

Understanding Android Activity Life Cycle

Firstly, to start creating your android app you must be clear with almost all of the basics that it takes for any developer to develop an android app. The basics to create your android app includes JAVA Programming, Understanding of Object Oriented Programming (OOPs) concepts, XML files and a good memory to remember these. If you want to become a good android developer for yourself, then these are the minimum required skills to take off. You can visit Programming Simplified also.

Lets first start with the Android Activity. Activity according to me is a web page as in a website. You can see the page and can interact with it to do something. Similarly, in android term, Activity is an application component that helps the users to interact with it using a screen for doing something. Examples: Take a photo, Call someone, Read Email, View a Map, etc.

How does it work actually? There is a life cycle attached to each and every activity through which it responds to and works accordingly. Let's say, for an example, you want to run your own business. For being able to run it, you will first of all start from somewhere. Maybe it could be like collecting money first up or getting a loan from a bank, joining your family business and learning it. Here in android, the activity starts running the same as to above mentioned lines. It initializes all of its components by running its onCreate() method.



 Before the activity is shown to the user it passes to three methods onCreate(), onStart(), onResume(). After the completion of onStart() and onResume() method, the activity is seen by the user but he/she can interact with it after onResume() method. At onPause(), the activity becomes invisible and the user cannot interact with it because another activity is working in the foreground. Then comes onStop() method where the activity becomes hidden from the user and it goes in the background where the code cannot execute for it. Last is the onDestroy() method where the activity is destroyed or stopped by the user.

Friday, February 12, 2016

Getting Started with Android Studio for Android App Development

Today, I am going to start with Android Studio. Android Studio is an IDE or Integrated Development Environment which is a software that helps Software Developers or Programmers to create an Android Application.

Before we dig in, let's get it for Android App Development.
It is better to use the latest version of Android Studio which is here. After downloading you can install it. Just follow the steps in the installation. If you have any queries then do contact me. After successful installation, just start Android Studio and follow the instructions shown as below to create your first android app.

1) This is the first screen that you will see after starting the android studio. Click on the 1st menu if you want to start a new Android Studio Project. If you have already created the project then go for the 2nd menu option to open an existing Android Studio Project.

Welcome to Android Studio

2) After clicking on Start new Project you will see the below screen. Here you have to type your Android Application Name. Be careful to write it here for like first and last time. You can change it but that will take some time for you to make a change at everywhere in your project. Second is the package name or the folder name where your app project will be stored. If suppose my package is com.parth.example.MyApp then there will be three folders in my system named "com", inside it "parth" and within it "example" Now "MyApp" project will be stored inside this example folder. Third is the App Location where you want to store the source code of your Android Application in your system.


New Android Project

3) Then comes the Target Devices Option Page where you can select the android device versions for supporting your application. Also, you can choose to create any Wearables, TV, Android Auto or Glass application.

Target Android Devices

4) Now here you will see a frame of some already created themes or mockups for your android app designed by the studio. Just select one of them as per your choice and go to next page.

Add Template Theme Activity to Mobile

5) Here you can provide a suitable class name for the first activity of your android app or leave it as it is. Just click on finish. That's it you have created your first simple "Hello World" Android Application in Android Studio.

Customize the Activity

6) Finally this is where you will end up after clicking the finish button in the above-mentioned image.

Android Studio Environment

This was the setup of your basic android app. Furthermore, I will put some interesting android app posts that will help you to learn more of this Android thing. Stay Tuned....

Thursday, February 11, 2016

Android StartUp

If you are a newbie in Android Development and want to Learn it, then here i am, starting to blog in some Android Tutorials on my own for everyone who wants to learn Android Application Development from Scratch.

But before doing that, let's go back in the year 2003 and take a look of how Android was originated. Android was founded by Andy Rubin, Rich Miner, Nick Sears and Chris White in Palo Alto, California in the year 2003.

Google acquired Android Corporation for $50 million in 2005. And the first ever Android built smartphone launched by Google was HTC Dream on October 22, 2008. After that, there has been no stopping to the world of smartphones, and of course Android, since we all know, how big is Google in developing newly defined gadgets and technologies that help most of us.

Android is built using Linux Kernel.Linux kernel is the heart of Linux operating system without which, the OS won't work as our body can't work without heart and mind. Further Android has its own Architecture or the Software Stack which is important to know how the application logic can be connected to the hardware parts of the machine in which you want to run your Android App. Here is the simple image which shows the Architecture of Android OS.


In the next blog i am going to start with the software with which you can start to create your own Android App.

Thursday, February 4, 2016

Knowing the Structure of Android App in terms of Software Engineering

Most of us want to know what is the best way of creating high quality apps in android or any other platform. But we tend to forget the basics of how to start creating apps that can become popular.


There are some things that you need to remember in order to create some good quality apps.

1) Analysis: Determine what information you have regarding the app idea that you wish to create. Try to enhance it by regularly collecting the info about your idea. This is where you would be thinking "Why to waste such time in collecting the info? It can be done while creating the app." Yes, it can be done, but at the time of developing the app, you won't be able to create the app in less time. Instead it will increase your developing time. Which is where you will sit ideally and think about collecting the info. So its better to try collecting Information ASAP.

2) Design: After that you have collected almost every bit of info about the idea that you want to create, try to design that idea into some animated graphics and awesome good looking images. Surely it will be good to look at. But remember that designing is next important part in developing any app. You need to start from logo and end up on to the last image or animation that will create some good motions in your app.

3) Developing: This is the third most important part of any app and this is where you want to showcase your coding skills. So start with all round performance by creating some good quality code and make sure that people who see your code also understand it better than you. There is a saying from Martin Fowler "Any fool can write code that a computer can understand. Good programmers write code that humans can understand." Try picking up some coding language and learn the basics of it. Remember it and then implement it in your app.

4) Testing: This is the last stage in creating any app, but not that this cycle has stopped after this. You have a lot to do after this step, if you've reached this far. Testing is not to be done here but, testing is the step which is accomplished throughout your apps creation. Testing is applied in all the above mentioned stages. In this stage(After Development Stage) you have to test your app in every aspect that comes to your mind. Test your app in almost every possible way, whether its cross platform or not, any devices like your own mobile or tablet or if it's a web app than test it in every different web browser. This is where your app is finalized to be distributed in the market and it will lend you some profit.

Well, this is it for this post where i have put some theory talk that may help you to understand the structure of any software that you want to build. After all, an android app is a software for mobiles.