[JAVA] Pre-written source code for the activity

I am a beginner. I wrote it for personal study.

Method executed when the app starts

HelloSampleActivity.java


package com.websarva.wings.android.hellosample;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class HelloSampleActivity extends AppCompatActivity {

	@override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);//--------------1
		setcontentView(R.layout.activity_hello_sample);//--2
	}
}

・ The above code is written in advance.

-Since the onCreate method is the method that is executed first when the Android application is executed, it is necessary to write in this method what is necessary for initial processing such as screen creation and data preparation.

-(1) calls the onCreate method of the parent class and describes the process. Since the Activity class must be created by inheriting the Activity class (or its child class), it is described by overriding the onCreate method defined in the Activity class.

・ ② sets the screen to be displayed by this app. The above code uses the one described in activity_hello_sample.xml as a screen, so the argument is "R.layout.activity_hello_sample".

R class

-In Android development, the files in the res folder and the ** resources ** described in those files are handled as the management target of the Android application.

-In order to manage resources efficiently, Android uses ** int type constant ** to identify the file value.

-The class that summarizes int type constants is ** R class , and Android studio automatically adds it to it. This allows resources to be exchanged using constants ( R-values **) in the R class.

-In Java, constants are written in capital letters, but for R values, the written folder names and file names are used as they are in order to clarify the relationship with the actual folder hierarchy and file names. using

Recommended Posts

Pre-written source code for the activity
Oracle Live for the Code
When reading the source code
Technology for reading source code (cheat sheet)
Source code for finding an orthonormal basis with the Gram-Schmidt orthogonalization method
Sample source code for finding the least common multiple of multiple values in Java
Rewrite the code for java.io.File with java.nio.Path and java.nio.Files
Include the source code generated by Doma in the source JAR
Specify VS Code as the default editor for jshell
[Android] Exit the activity of the transition source at the time of screen transition
Specify the character code of the source when building with Maven
I tried source code analysis
[Java] Tips for writing source
What is the constructor for?
Until the code is executed
Use an example domain for the package name in the sample code
[Reference example] Copyright is described in the comment of the source code.