Sunday, October 16, 2016

I want to learn android programming from zero

You never do any programming before and you don't study computer science either. But you really want to make an android app. Maybe you are inspired by young people there in the world who have gained a lot of money and become millionaire in their country by making apps or games that luckily becomes so popular. Don't worried. You are in the right place here.

Learning android programming to make apps does not difficult at all. It does not require high math skills unless if you want to invent a new algorithm for search engine. To make you comfort with android programming you just have to change your mindset that everything is object. Yes, Android uses Java and it is one of Object Oriented Programming (OOP). Everything you see or not see in android app is an object. That object also contains other objects. When you click a button, that button is an object. When you see a  page screen that screen is also an object and it contains other objects like button. When you send a message it also create an http object where you can not see.  Even the application itself is an object. So right now look at java codes in android and view it as object. Okay, I think it is clear now and you want to rush to coding.

To start writing code you need to open Android Studio and launch a new project. see :make my first app. After you click next next next and so on, then you finish. Click run button in Android Studio menu and your app will be built, a "hello word" text is shown to you. That is android application. You still don't write any code yet. But the app is there has been created for you by Android Studio. Well well,  At this time you are not supposed to write  any code yet, but you need to understand what has been written to you by android studio. 

When you launch a new project and then click finish at the end the android studio creates some folders and files for the app. The most important file you need to understand is AndroidManifest.xml. 

Below is the example of AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="com.example.myapplication.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


This manifest file tells you a lot information about the application. All of your activity should be registered in this manifest otherwise will not work. The highest hierarchy in manifest is <application> tag. That is your application, it contains activity as the children. When you first install your application from google play store or from apk file or you build from android studio the android system create your application object. Now start thinking that you app is an object. Now click the app icon in home menu screen then it will display a page (page is activity), which activity is displayed first?. Allright,  this manifest will tell you. That the activity that has been declared with intent-filter
as android.intent.category.LAUNCHER will displayed first. Okay now clear to you that why I should see that page. Now let's go back to object thinking. Now when it lauch that activity it creates that activity object, well activity is an object now. Let's see an example of activity code :
package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
    }
}

See that MainActivity extends Activity, Activity is a class from Android Library SDK, you don't write it, the google team write it for you, you just extends it. That activity calls onCreate method and set content to your page in  line setContentView(R.layout.activity_main); That is why you see layout activity_main.xml is shown to you. You put activity_main.xml in layout folder under res folder separated from java files, to make easier for you to manage source code. see : explore android studio folders and files. If you have understand this basic concept you are ready for next lessons. keep in mind that everything is object.


Thank you for visiting our website. Just comment below if you have any question to ask.



No comments:

Post a Comment