Skip to main content

Android : Activity

An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.[1]

An Activity is a screen in which user perform some task. It might be capturing image, dialing phone number, typing text message etc. These all are the activities. Almost every screen with which users interact is an activity.



In activity we make the UI by setting method called: setContentView(View)
   There are mainly two methods which we use in almost every activity:

  •  onCreate(Bundle): This method initializes your activity. And in this method we invoke setContentView(int). In setContentView(int) method we pass layout resource which creates UI for an activity. And findViewById(int) is the another method which is used in OnCreate(Bundle) to retrieve all the widgets in the UI.


  • onPause():  This is required to deal the situation when user is leaving an activity.


Activity Life Cycle:
  • onCreate()
  • onStart()
  • onResume()
  • onPause()
  • onStop()
  • onRestart()
  • onDestroy()

Multiple Activities:

Android uses stack mechanism for handling multiple activities. It puts the activity in stack when other activity is called. And also retrieves the activities back in the same manner i.e. Last In First Out. It pops up the recently added activity and destroys it.

Activity 4
Activity 3
Activity 2
Activity 1


  

Comments

Post a Comment

Popular posts from this blog

Android: Login Screen using Fragments

In this tutorial, our focus is on making a User/Member login activity using fragments. With the help of Fragments we will use the same activity to show User login area and also Members Login area. Prerequisite for this tutorial: You should be know how to make an Activity And most importantly you should have prior Knowledge of Fragments. For practising basic Fragment implementation refer to Android Simple Fragment Example      We have used only three activities for this: MainActivity(which represents the Login Screen) Fragments for Members area Fragment for New Users

Simple Login/Register Example using SQLite database

MainActivity.java(login Screen) package com.AndroidDevelopmentGuru.database_new; import java.util.List; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity {                                 EditText user, pass;                 Button login, not_reg;                 DatabaseHandler db;           ...

Android: How to Generate Key Hash for Facebook Integration

Hello everyone, As this is a quite confusing for everyone to generate the key hash in your PC, so i decided to write about it. I have also tried many ways but every time i failed to generate the key hash. After trying for an hour i successfully generated the key. Just follow the below given Steps and you are done with this. Step I: Download Openssl from   here Step II: Download openssl-0.9.8e_X64.zip for 64 bit PC and openssl-0.9.8e_WIN32.zip for 32 bit PC Step III: once your download the zip folder. Go to C drive(where window is installed) and make a folder named openssl Step IV: extract all zip file in this folder. Step V: Now go to Java folder and copy path of jre. For example: C:\Program Files\Java\jre1.8.0_101\bin