Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Introduction</strong></p> <p>In Android, an Activity is one of the several components that can make up an Android Application. What distinguishes an Activity from all other components is that it is the only component that can (and must) have a user interface. Since most applications are not useful without some way for the user to interact with the program, Activities are the most common components, as nearly every application has at least one and some have many.</p> <p>For security and user protection, there are many things that can only be done from an Activity. </p> <p><strong>Creating an Activity</strong></p> <p>The Activity class is a base class and must be extended for each and every Activity that you want to include. In order for an Activity to run, there is some amount of Java code required. This means that some level of Java expertise is also required. Once the code has been assembled, it is ready to be used by the system.</p> <p>In order for an Activity to be called by the system (or any other app, including the home launcher), it must know that it exists. Each and every Activity must be declared in the AndroidManifest.xml by using an <code>&lt;activity&gt;</code>-tag. </p> <ul> <li>Questions regarding the Android Manifest should refer to <a href="/questions/tagged/android-manifest" class="post-tag" title="show questions tagged &#39;android-manifest&#39;" rel="tag">android-manifest</a>.</li> </ul> <p><strong>The User Interface</strong></p> <p>In Android, the user interface of an Activity is called the Layout. The Layout is a hierarchy of extended Views that are rendered to the screen. Layouts may be created using either by using <a href="https://developer.android.com/guide/topics/ui/declaring-layout.html" rel="nofollow noreferrer">XML</a> or <a href="https://developer.android.com/reference/android/widget/package-summary.html" rel="nofollow noreferrer">Java code</a>. Regardless of which method was used to create the Layout, it may always be modified by Java code. </p> <ul> <li>Questions regarding layout should refer to <a href="/questions/tagged/android-layout" class="post-tag" title="show questions tagged &#39;android-layout&#39;" rel="tag">android-layout</a>. </li> <li>Layout defined by android XML may also utilize the <a href="/questions/tagged/android-xml" class="post-tag" title="show questions tagged &#39;android-xml&#39;" rel="tag">android-xml</a> tag.</li> </ul> <p><strong>The Activity LifeCycle</strong></p> <p>Every Activity in Android is subject to a LifeCycle. The LifeCycle performs the job of notifying the Activity when certain events have occurred, allowing the program to respond to them accordingly, if needed. This happens from the point that an Activity is started (<code>onCreate()</code>) all the way until the Activity is killed (<code>onDestroy()</code>). The LifeCycle events make no distinction between user-initiated events or simulated events. </p> <p>Due to the imposition of the LifeCycle on all Activities, it is very important to be aware which methods are called and when, as some of them can affect the stability of the application if not accounted for. Each has its own arguments for processing and many are repeated throughout the life of the Activity. The Android LifeCycle consists of the following methods (not necessarily in order): <code>onCreate()</code>, <code>onStart()</code>, <code>onResume()</code>, <code>onConfigurationChanged()</code>, <code>onRestoreInstanceState()</code>, <code>onPause()</code>, <code>onSaveInstanceState()</code>, <code>onStop()</code>, and <code>onDestroy()</code>.</p> <p><img src="https://i.stack.imgur.com/BKoFw.png" alt="Android Activity lifecycle"></p> <ul> <li>Questions regarding the LifeCycle should also use the tag <a href="/questions/tagged/android-lifecycle" class="post-tag" title="show questions tagged &#39;android-lifecycle&#39;" rel="tag">android-lifecycle</a>.</li> </ul> <p><strong>Activities and Contexts</strong></p> <p>Contexts are used often in Android to attribute certain actions to a task. They also help by routing operations that may run outside the developer's code so that it is attributed to the correct instance of the Activity. While there are several kinds of Contexts, Activity is also a Context and most methods that require one will easily accept a reference to the Activity. </p> <p><strong>Further reading:</strong></p> <ul> <li><a href="https://developer.android.com/guide/topics/fundamentals/activities.html" rel="nofollow noreferrer">Activities Developer Guide</a></li> <li><a href="https://developer.android.com/reference/android/app/Activity.html" rel="nofollow noreferrer">Activity Class Reference</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload