android-activity

Getting started with android-activity

Remarks#

This section provides an overview of what android-activity is, and why a developer might want to use it.

It should also mention any large subjects within android-activity, and link out to the related topics. Since the Documentation for android-activity is new, you may need to create initial versions of those related topics.

Installation or Setup

Detailed instructions on getting android-activity set up or installed.

Activity

Activity is complete screen. UI is XML based and

package com.example.android.activity;

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

public class MainActivity extends Activity {

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

NOTE Activity must be declared in AndroidManifest.xml before using it.

E.g:

<activity android:name=".MainActivity">
     <intent-filter>
         <action android:name="android.intent.action.MAIN" />

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

Every activity has its layout file in xml format, we include its layout using setContentView method of Activity class. E.g. setContentView(R.layout.activity_main)

Layout file example

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools"
    android:id="@+id/activity_dashboard"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    //Add other views here

</LinearLayout>

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow