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;                 Cursor cursor;                                 @Override                 protected void onCreate(Bundle savedInstanceState) {                                 super.onCreate(savedInstanceState);                                 setContentView(R.layout.activity_main);

Android: Current Location Using Fused APi on Google Maps

This tutorial gives us the simple implementation of "Fused API" to fetch the current location on google map in android. Fused API is latest among all techniques to get the location. It provides you very precise results and also uses less battery of your device. It chooses GPS or Network provider to get to your current location. And it helps your device remember about the last saved location. Let's implement the Fused API to fetch/get the current location. Step 1: Create a new project in Android studio. and select Maps Activity.