SlideShare a Scribd company logo
ACTIVITY
Activity Life Cycle:
onCreate

          Called when your activity is first created. This is the place you normally create your views, open any
          persistent datafiles your activity needs to use, and in general initialize your activity. When calling
          onCreate, the Android framework is passed a Bundle object that contains any activity state saved from
          when the activity ran before.

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

                   Log.i(TAG,”On Create”);
                   }




onResume

          Called right after onStart if your activity is the foreground activity on the screen. At this point your
          activity is running and interacting with the user. You are receiving keyboard and touch inputs, and the
          screen is displaying your user interface. onResume is also called if your activity loses the foreground to
          another activity, and that activity eventually exits, popping your activity back to the foreground. This is
          where your activity would start (or resume) doing things that are needed to update the user interface
          (receiving location updates or running an animation, for example).

                   @Override
                   protected void onResume() {
                   // TODO Auto-generated method stub
                   super.onResume();
                   Log.i(TAG,”On Resume”);
                   }




onPause

          Called when Android is just about to resume a different activity, giving that activity the foreground. At this
          point your activity will no longer have access to the screen, so you should stop doing things that consume
          battery and CPU cycles unnecessarily. If you are running an animation, no one is going to be able to see it,
          so you might as well suspend it until you get the screen back. Your activity needs to take advantage of this
          method to store any state that you will need in case your activity gains the foreground again—and it is not
          guaranteed that your activity will resume. If the mobile device you are running on runs out of memory,
          there is no virtual memory on disk to use for expansion, so your activity may have to make way for a
          system process that needs memory. Once you exit this method, Android may kill your activity at any time
          without returning control to you.

                            @Override
                            protected void onPause() {
                            // TODO Auto-generated method stub
                            super.onPause();
Log.i(TAG,”On Pause”);
                           }




onStop

         Called when your activity is no longer visible, either because another activity has taken the foreground or
         because your activity is being destroyed.

                           @Override
                           protected void onStop() {
                           // TODO Auto-generated method stub
                           super.onStop();
                           Log.i(TAG,”On Stop”);
                           }




onDestroy

         The last chance for your activity to do any processing before it is destroyed. Normally you'd get to this
         point because the activity is done and the framework called its finish method. But as mentioned earlier,
         the method might be called because Android has decided it needs the resources your activity is consuming.

                  @Override
                  protected void onDestroy() {
                  // TODO Auto-generated method stub
                  super.onDestroy();

                  Log.i(TAG,”On Destroy”);
                  }




From One Activity to another activity:

         Suppose we want to go mainActivity to nextActivity

             Add this activity in AndroidManifest.xml file

             <application android:icon="@drawable/icon"
             android:label="@string/app_name">

             <activity android:name="clubNewsActivity" ></activity>

             </application>
So In mainActivity:

Intent i = new Intent(mainActivity.this, nextActivity.class);

startActivity(i);




Value pass one to activity to another

If you want to pass some value from this activity to next activity.You have
to do below:

In mainActivity:
Intent i = new Intent(mainActivity.this,
nextActivity.class);

i.putExtra("id", "2");

i.putExtra("Name", "Karim");

startActivity(i);

In nextActivity:
@Override
public void onCreate(Bundle savedInstanceState) {

           super.onCreate(savedInstanceState);

       String Id=getIntent().getStringExtra("id");

        String Name=getIntent().getStringExtra("Name");

}

More Related Content

What's hot (20)

PDF
Android Basic Components
Jussi Pohjolainen
 
PPTX
Android Life Cycle
mssaman
 
PPTX
Presentation on Android application life cycle and saved instancestate
Osahon Gino Ediagbonya
 
PPT
Android Basics
Krushnakant Solanki
 
PDF
Android UI Fundamentals part 1
Marcos Paulo Souza Damasceno
 
ODP
Ppt 2 android_basics
Headerlabs Infotech Pvt. Ltd.
 
PPTX
Android Widget
ELLURU Kalyan
 
PPT
Day 4: Android: UI Widgets
Ahsanul Karim
 
PPTX
Android apps development
Raman Pandey
 
PPTX
Android components
NAVEENA ESWARAN
 
PPT
View groups containers
Mani Selvaraj
 
PDF
Android Components & Manifest
ma-polimi
 
PDF
Android development session 4 - Fragments
Farabi Technology Middle East
 
PPTX
Android application-component
Ly Haza
 
PPT
android layouts
Deepa Rani
 
PDF
Android session 2
Ahesanali Suthar
 
PDF
Android session 3
Ahesanali Suthar
 
PDF
04 user interfaces
C.o. Nieto
 
PDF
Android session 1
Ahesanali Suthar
 
DOCX
Activity
roopa_slide
 
Android Basic Components
Jussi Pohjolainen
 
Android Life Cycle
mssaman
 
Presentation on Android application life cycle and saved instancestate
Osahon Gino Ediagbonya
 
Android Basics
Krushnakant Solanki
 
Android UI Fundamentals part 1
Marcos Paulo Souza Damasceno
 
Ppt 2 android_basics
Headerlabs Infotech Pvt. Ltd.
 
Android Widget
ELLURU Kalyan
 
Day 4: Android: UI Widgets
Ahsanul Karim
 
Android apps development
Raman Pandey
 
Android components
NAVEENA ESWARAN
 
View groups containers
Mani Selvaraj
 
Android Components & Manifest
ma-polimi
 
Android development session 4 - Fragments
Farabi Technology Middle East
 
Android application-component
Ly Haza
 
android layouts
Deepa Rani
 
Android session 2
Ahesanali Suthar
 
Android session 3
Ahesanali Suthar
 
04 user interfaces
C.o. Nieto
 
Android session 1
Ahesanali Suthar
 
Activity
roopa_slide
 

Viewers also liked (20)

PPT
Day 6: Android BroadcastReceiver Component
Ahsanul Karim
 
PDF
Day 2 android internals a quick overview
Ahsanul Karim
 
PDF
Day 1 Android: Before Getting Started
Ahsanul Karim
 
PPT
Day 5: Android User Interface [View Widgets]
Ahsanul Karim
 
PDF
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
PPTX
Day 15: Working in Background
Ahsanul Karim
 
PPTX
Day 15: Content Provider: Using Contacts API
Ahsanul Karim
 
PPTX
Day 9: Make Your App Location Aware using Location API
Ahsanul Karim
 
PPTX
Client-Server
Ahsanul Karim
 
PPTX
Android GPS Tutorial
Ahsanul Karim
 
PPTX
Android Services
Ahsanul Karim
 
PPTX
Android Application Component: BroadcastReceiver Tutorial
Ahsanul Karim
 
PPT
Day 3: Getting Active Through Activities
Ahsanul Karim
 
PDF
লেকচার ১ (ক)- শুরুর আগে:
Ahsanul Karim
 
PPT
Day: 2 Environment Setup for Android Application Development
Ahsanul Karim
 
PPTX
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Ahsanul Karim
 
PPT
Android User Interface: Basic Form Widgets
Ahsanul Karim
 
PPTX
Day: 1 Introduction to Mobile Application Development (in Android)
Ahsanul Karim
 
PPTX
Introduction To Mobile Application Development
Syed Absar
 
PDF
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
SlideShare
 
Day 6: Android BroadcastReceiver Component
Ahsanul Karim
 
Day 2 android internals a quick overview
Ahsanul Karim
 
Day 1 Android: Before Getting Started
Ahsanul Karim
 
Day 5: Android User Interface [View Widgets]
Ahsanul Karim
 
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Day 15: Working in Background
Ahsanul Karim
 
Day 15: Content Provider: Using Contacts API
Ahsanul Karim
 
Day 9: Make Your App Location Aware using Location API
Ahsanul Karim
 
Client-Server
Ahsanul Karim
 
Android GPS Tutorial
Ahsanul Karim
 
Android Services
Ahsanul Karim
 
Android Application Component: BroadcastReceiver Tutorial
Ahsanul Karim
 
Day 3: Getting Active Through Activities
Ahsanul Karim
 
লেকচার ১ (ক)- শুরুর আগে:
Ahsanul Karim
 
Day: 2 Environment Setup for Android Application Development
Ahsanul Karim
 
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Ahsanul Karim
 
Android User Interface: Basic Form Widgets
Ahsanul Karim
 
Day: 1 Introduction to Mobile Application Development (in Android)
Ahsanul Karim
 
Introduction To Mobile Application Development
Syed Absar
 
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
SlideShare
 
Ad

Similar to Day 4: Activity lifecycle (20)

PDF
02 programmation mobile - android - (activity, view, fragment)
TECOS
 
PPT
Activities
Sourabh Sahu
 
PPTX
Activity lifecycle
Rehan Choudhary
 
ODP
Anatomy of android application
Nikunj Dhameliya
 
PPTX
Architecting Single Activity Applications (With or Without Fragments)
Gabor Varadi
 
PPTX
Lecture 6: Android Activity Life Cycle.pptx
Yousef Alamir
 
PPTX
04 activities and activity life cycle
Sokngim Sa
 
PDF
More android code puzzles
Danny Preussler
 
PPTX
Lecture #4 activities &amp; fragments
Vitali Pekelis
 
PDF
Android life cycle
瑋琮 林
 
PPTX
How to recognise that the user has just uninstalled your android app
Przemek Jakubczyk
 
PPTX
How to recognise that the user has just uninstalled your android app droidc...
Przemek Jakubczyk
 
PPT
Introduction to android
Arbuleac Eugeniu
 
PPTX
Unit-1.2 Android-Activities, Fragments, and Intents (1).pptx
vikasR48
 
PPTX
Designing for Windows Phone 8
David Isbitski
 
PDF
Quick Intro to Android Development
Jussi Pohjolainen
 
PDF
Android development Training Programme Day 2
DHIRAJ PRAVIN
 
PDF
Introduction toandroid
Google Developer Group Bucharest
 
PPTX
Lesson 4
CITSimon
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
02 programmation mobile - android - (activity, view, fragment)
TECOS
 
Activities
Sourabh Sahu
 
Activity lifecycle
Rehan Choudhary
 
Anatomy of android application
Nikunj Dhameliya
 
Architecting Single Activity Applications (With or Without Fragments)
Gabor Varadi
 
Lecture 6: Android Activity Life Cycle.pptx
Yousef Alamir
 
04 activities and activity life cycle
Sokngim Sa
 
More android code puzzles
Danny Preussler
 
Lecture #4 activities &amp; fragments
Vitali Pekelis
 
Android life cycle
瑋琮 林
 
How to recognise that the user has just uninstalled your android app
Przemek Jakubczyk
 
How to recognise that the user has just uninstalled your android app droidc...
Przemek Jakubczyk
 
Introduction to android
Arbuleac Eugeniu
 
Unit-1.2 Android-Activities, Fragments, and Intents (1).pptx
vikasR48
 
Designing for Windows Phone 8
David Isbitski
 
Quick Intro to Android Development
Jussi Pohjolainen
 
Android development Training Programme Day 2
DHIRAJ PRAVIN
 
Introduction toandroid
Google Developer Group Bucharest
 
Lesson 4
CITSimon
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Ad

More from Ahsanul Karim (18)

PDF
Lecture 5: Storage: Saving Data Database, Files & Preferences
Ahsanul Karim
 
PDF
Lecture 3 getting active through activities
Ahsanul Karim
 
PDF
Lecture 2(b) Android Internals A Quick Overview
Ahsanul Karim
 
PDF
Lecture 1 Session 1 Before Getting Started
Ahsanul Karim
 
PDF
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
PDF
Mobile Banking in Bangladesh: An Incomplete Study
Ahsanul Karim
 
PDF
GCM for Android
Ahsanul Karim
 
PDF
List Views
Ahsanul Karim
 
PDF
Ui layout (incomplete)
Ahsanul Karim
 
PDF
AndroidManifest
Ahsanul Karim
 
PDF
Sensors in Android (old)
Ahsanul Karim
 
PDF
Day1 before getting_started
Ahsanul Karim
 
PPTX
Action Bar Sherlock tutorial
Ahsanul Karim
 
PPTX
Android Workshop: Day 1 Part 3
Ahsanul Karim
 
PPTX
Android Workshop Day 1 Part 2
Ahsanul Karim
 
PPTX
Android 1.8 sensor
Ahsanul Karim
 
PPTX
Android before getting started
Ahsanul Karim
 
PPTX
Introduction to Android Development: Before Getting Started
Ahsanul Karim
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Ahsanul Karim
 
Lecture 3 getting active through activities
Ahsanul Karim
 
Lecture 2(b) Android Internals A Quick Overview
Ahsanul Karim
 
Lecture 1 Session 1 Before Getting Started
Ahsanul Karim
 
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Mobile Banking in Bangladesh: An Incomplete Study
Ahsanul Karim
 
GCM for Android
Ahsanul Karim
 
List Views
Ahsanul Karim
 
Ui layout (incomplete)
Ahsanul Karim
 
AndroidManifest
Ahsanul Karim
 
Sensors in Android (old)
Ahsanul Karim
 
Day1 before getting_started
Ahsanul Karim
 
Action Bar Sherlock tutorial
Ahsanul Karim
 
Android Workshop: Day 1 Part 3
Ahsanul Karim
 
Android Workshop Day 1 Part 2
Ahsanul Karim
 
Android 1.8 sensor
Ahsanul Karim
 
Android before getting started
Ahsanul Karim
 
Introduction to Android Development: Before Getting Started
Ahsanul Karim
 

Day 4: Activity lifecycle

  • 2. onCreate Called when your activity is first created. This is the place you normally create your views, open any persistent datafiles your activity needs to use, and in general initialize your activity. When calling onCreate, the Android framework is passed a Bundle object that contains any activity state saved from when the activity ran before. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Log.i(TAG,”On Create”); } onResume Called right after onStart if your activity is the foreground activity on the screen. At this point your activity is running and interacting with the user. You are receiving keyboard and touch inputs, and the screen is displaying your user interface. onResume is also called if your activity loses the foreground to another activity, and that activity eventually exits, popping your activity back to the foreground. This is where your activity would start (or resume) doing things that are needed to update the user interface (receiving location updates or running an animation, for example). @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); Log.i(TAG,”On Resume”); } onPause Called when Android is just about to resume a different activity, giving that activity the foreground. At this point your activity will no longer have access to the screen, so you should stop doing things that consume battery and CPU cycles unnecessarily. If you are running an animation, no one is going to be able to see it, so you might as well suspend it until you get the screen back. Your activity needs to take advantage of this method to store any state that you will need in case your activity gains the foreground again—and it is not guaranteed that your activity will resume. If the mobile device you are running on runs out of memory, there is no virtual memory on disk to use for expansion, so your activity may have to make way for a system process that needs memory. Once you exit this method, Android may kill your activity at any time without returning control to you. @Override protected void onPause() { // TODO Auto-generated method stub super.onPause();
  • 3. Log.i(TAG,”On Pause”); } onStop Called when your activity is no longer visible, either because another activity has taken the foreground or because your activity is being destroyed. @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); Log.i(TAG,”On Stop”); } onDestroy The last chance for your activity to do any processing before it is destroyed. Normally you'd get to this point because the activity is done and the framework called its finish method. But as mentioned earlier, the method might be called because Android has decided it needs the resources your activity is consuming. @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); Log.i(TAG,”On Destroy”); } From One Activity to another activity: Suppose we want to go mainActivity to nextActivity Add this activity in AndroidManifest.xml file <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name="clubNewsActivity" ></activity> </application>
  • 4. So In mainActivity: Intent i = new Intent(mainActivity.this, nextActivity.class); startActivity(i); Value pass one to activity to another If you want to pass some value from this activity to next activity.You have to do below: In mainActivity: Intent i = new Intent(mainActivity.this, nextActivity.class); i.putExtra("id", "2"); i.putExtra("Name", "Karim"); startActivity(i); In nextActivity: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String Id=getIntent().getStringExtra("id"); String Name=getIntent().getStringExtra("Name"); }