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

PPT
Day 4: Android: Getting Active through Activities
PDF
Android development - Activities, Views & Intents
PPTX
04 activities - Android
PPTX
Android MapView and MapActivity
PPT
Multiple Activity and Navigation Primer
PPT
android activity
PDF
Android activities & views
PPT
Day 3: Getting Active Through Activities
Day 4: Android: Getting Active through Activities
Android development - Activities, Views & Intents
04 activities - Android
Android MapView and MapActivity
Multiple Activity and Navigation Primer
android activity
Android activities & views
Day 3: Getting Active Through Activities

What's hot (20)

PDF
Android Basic Components
PPTX
Android Life Cycle
PPTX
Presentation on Android application life cycle and saved instancestate
PPT
Android Basics
PDF
Android UI Fundamentals part 1
ODP
Ppt 2 android_basics
PPTX
Android Widget
PPT
Day 4: Android: UI Widgets
PPTX
Android apps development
PPTX
Android components
PPT
View groups containers
PDF
Android Components & Manifest
PDF
Android development session 4 - Fragments
PPTX
Android application-component
PPT
android layouts
PDF
Android session 2
PDF
Android session 3
PDF
04 user interfaces
PDF
Android session 1
DOCX
Activity
Android Basic Components
Android Life Cycle
Presentation on Android application life cycle and saved instancestate
Android Basics
Android UI Fundamentals part 1
Ppt 2 android_basics
Android Widget
Day 4: Android: UI Widgets
Android apps development
Android components
View groups containers
Android Components & Manifest
Android development session 4 - Fragments
Android application-component
android layouts
Android session 2
Android session 3
04 user interfaces
Android session 1
Activity
Ad

Viewers also liked (20)

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

Similar to Day 4: Activity lifecycle (20)

PDF
02 programmation mobile - android - (activity, view, fragment)
PPT
Activities
PPTX
Activity lifecycle
ODP
Anatomy of android application
PPTX
Architecting Single Activity Applications (With or Without Fragments)
PPTX
Lecture 6: Android Activity Life Cycle.pptx
PPTX
04 activities and activity life cycle
PDF
More android code puzzles
PPTX
Lecture #4 activities &amp; fragments
PDF
Android life cycle
PPTX
How to recognise that the user has just uninstalled your android app
PPTX
How to recognise that the user has just uninstalled your android app droidc...
PPT
Introduction to android
PPTX
Unit-1.2 Android-Activities, Fragments, and Intents (1).pptx
PPTX
Designing for Windows Phone 8
PDF
Quick Intro to Android Development
PDF
Android development Training Programme Day 2
PDF
Introduction toandroid
PPTX
Lesson 4
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
02 programmation mobile - android - (activity, view, fragment)
Activities
Activity lifecycle
Anatomy of android application
Architecting Single Activity Applications (With or Without Fragments)
Lecture 6: Android Activity Life Cycle.pptx
04 activities and activity life cycle
More android code puzzles
Lecture #4 activities &amp; fragments
Android life cycle
How to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android app droidc...
Introduction to android
Unit-1.2 Android-Activities, Fragments, and Intents (1).pptx
Designing for Windows Phone 8
Quick Intro to Android Development
Android development Training Programme Day 2
Introduction toandroid
Lesson 4
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)

More from Ahsanul Karim (18)

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

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"); }