Main activity file
The main operation code is the Java MainActivity.java file. This is the actual application file that ultimately converts to the Dalvik executable file and launches your application. The following is the default code generated by the application wizard for Hello World! Appendix -
package com.example.helloworld; import android.support.v7.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); } }
Manifest file
No matter which component you are developing as part of your application, you must declare all its components in the manifest.xml file, which is located in the root of the application project directory. This file works as an interface between the Android OS and your application, so if you do not declare your component in this file, it will not be considered by the OS. For example, the default manifest file would look like this:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.tutorialspoint7.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=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
Line file
The strings.xml file is located in the res / values folder and contains all the text that your application uses. For example, the names of buttons, labels, default text, and similar line types are included in this file. This file is responsible for their text content. For example, the default line file would look like this:
<resources> <string name="app_name">HelloWorld</string> <string name="hello_world">Hello world!</string> <string name="menu_settings">Settings</string> <string name="title_activity_main">MainActivity</string> </resources>
Layout file
Activity_main.xml is a layout file available in the res / layout directory that your application refers to when building its interface. You will modify this file very often to change the layout of your application. For your "Hello World!" application, this file will have the following content associated with the default layout -
<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" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:padding="@dimen/padding_medium" android:text="@string/hello_world" tools:context=".MainActivity" /> </RelativeLayout>