On Fri, 11 Dec 2020 06:09:34 -0000 (UTC), Arlen Holder wrote:
This hello-world tutorial app contained the following key components:
1. app > manifests > AndroidManifest.xml
o Describes the characteristics of the app & each of its components.
2. app > java > com.foo.app01_hello > MainActivity
o Contains the src JAVA that runs when the app icon is launched.
3. app > res > layout > activity_main.xml
o Define your app's user interface.
Each of those key files has a job to perform when the app is launched:
1. app > manifests > AndroidManifest.xml
This is the XML description of the key characteristics of your app.
For example, it defines the default "schema" your app will be using.
And it defines your unique "package name" of "com.foo.app01_hello".
It defines what icon the app uses & the name associated with the icon.
o action
o category
o Six methods run, starting with onCreate, onStart, and then onResume
o Later onPause will run, and then onStop, and, finally, onDestroy.
2. app > java > com.foo.app01_hello > MainActivity
This is the Java "entry point" when you run the app on your phone.
Tapping the app on your phone launches this "Activity".
The "Layout" is also displayed when this activity launches.
o extends
o @Override
3. app > res > layout > activity_main.xml
This is the XML definition of your app's "Layout" or User Interface.
In this case, there's a simple "Text View" "Element".
That Text View Element outputs "Hello World!".
Looking at the code flow...
1. app > manifests > AndroidManifest.xml
The "action" element indicates the activity that's set forth.
Being "MAIN" means that's the starting point of the app's execution.
The code's "onCreate" method will be what's actually launched.
The category element's "LAUNCHER" value makes an icon for running
the MainActivity class available on the device's Launcher screen.
2. app > java > com.foo.app01_hello > MainActivity
The "extends" allows calls to the many AppCompatActivity APIs.
The "@Override" can replace pre-existing code.
This is used to tell Android not to use the pre-existing onCreate method.
Instead, the MainActivity contains a declaration for its own onCreate method.
The onCreate method calls setContentView(R.layout.activity_main),
which displays what's described in the res/layout/activity_main.xml file.
Rather than override the onStart and onResume methods, this app employs
the AppCompatActivity class's prewritten onStart and onResume methods.
When an Android device ends an activity's run, the device calls three
pre-defined methods: the activity's onPause, onStop, & onDestroy methods.
3. app > res > layout > activity_main.xml
This is an example of a simple RelativeLayout.
The TextView is an Android control used to build the GUI.
It has attributes such as android:layout_width, android:layout_height.
The "text" is the text string that will be output (i.e., "Hello World!").
The actual code is shown below:
1. app > manifests > AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"
package="com.foo.app01_hello">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.App01_hello">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
2. app > java > com.foo.app01_hello > MainActivity
package com.foo.app01_hello;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
3. app > res > layout > activity_main.xml
(Note: Normally you modify this XML code via a graphical method.)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="
http://schemas.android.com/apk/res/android"
xmlns:app="
http://schemas.android.com/apk/res-auto"
xmlns:tools="
http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
In summary, each file defines key tasks, such as:
1. app > manifests > AndroidManifest.xml
Name ==> com.foo.app01_hello
Icon ==> ic_launcher
Label ==> app01_hello
2. app > java > com.foo.app01_hello > MainActivity
Layout ==> activity_main.xml
3. app > res > layout > activity_main.xml
MainActivity ==> TextView ==> "Hello World!"
Please improve so that all benefit from every action you take.
--
Posted out of the goodness of my heart, to help everyone create apps.