Getting started with android-activity

Download android-activity eBook

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.

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="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_dashboard"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    //Add other views here

</LinearLayout>
 

Installation or Setup

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

Stats

39 Contributors: 2
Tuesday, May 23, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook