SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
Workshop India
» An activity is the equivalent of a Frame/Window in
  GUI toolkits. It takes up the entire drawable area
  of the screen (minus the status and title bars on
  top).
» Activities are meant to display the UI and get input
  from the user.
» Activities can be frozen when the focus is switched
  away from them (eg: incoming phone call).
» Services on the other hand keep running for the
  duration of the user’s ‘session’ on the device.
» Any screen state is called an activity.

» An Application always starts with a main activity

» An application can have multiple activities that the
  user moves in and out of.

» A stack of activities is maintained by the android
  system to handle back presses and returns.
» In res/layout we’ll need to make 2 xml files each
  defining the layout for the individual activity.
   ˃ main.xml
   ˃ second.xml


» Each activity needs an activity class associated
  with it, these are present in the /src folder
   ˃ mainActivity.java -> main.xml
   ˃ secondActivity.java -> second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/linearLayout1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >

  <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I&apos;m screen 1 (main.xml)"
    android:textAppearance="?android:attr/textAppearanceLarge" />

  <Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"                     Button that we’ll
    android:layout_height="wrap_content"                   use to move to the
    android:text="Click me to another screen" />           next activity
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/linearLayout1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" >

  <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I&apos;m screen 2 (second.xml)"
    android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>
package com.wingie;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class mainactivity extends Activity {
  Button button;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
setContentView(R.layout.main);
      addListenerOnButton();
    }
    public void addListenerOnButton() {
      final Context context = this;
      button = (Button) findViewById(R.id.button1);
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            Intent intent = new Intent(context, second.class);
            startActivity(intent);
          }
      });              Then we create an
    }                  intent to move to the
                    next activity,
}                   (Second.java)
04   activities - Android
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.wingie"
     android:versionCode="1"
     android:versionName="1.0">
  <uses-sdk android:minSdkVersion="13"/>
  <application android:label="@string/app_name">
    <activity android:name=".main"
          android:label="@string/app_name">
      <intent-filter>
         <action android:name="android.intent.action.MAIN"/>
         <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>
    <activity                      This describes the
                                   second activity in
         android:label="@string/app_name"
                                   the application
         android:name=".second" >
    </activity>
  </application>
</manifest>
The super.fn() makes sure that the
                                                       overridden method is also called
                                                       before any of our code runs..



public class ExampleActivity extends Activity {
@Override
  public void onCreate(Bundle savedInstanceState) {   The activity is being created.
    super.onCreate(savedInstanceState);
}

@Override
  protected void onStart() {                          The activity is about to
                                                      become visible.
    super.onStart();
}

@Override
  protected void onResume() {                         The activity has become
                                                      visible (it is now "resumed").
    super.onResume();
}
@Override
                                 Another activity is taking
    protected void onPause() {
                                 focus (this activity is about
      super.onPause();           to be "paused").
}

@Override
  protected void onStop() {
    super.onStop();              The activity is no longer
}                                visible (it is now "stopped")

@Override
 protected void onDestroy() {
   super.onDestroy();
                                 The activity is about to be
    }                            destroyed.
}
04   activities - Android
» A Fragment represents a behavior or a portion of
  user interface in an Activity.

» A fragment must always be embedded in an
  activity
   ˃ fragment's lifecycle is directly affected by the host activity's lifecycle.


» You can insert a fragment into your activity layout
   ˃ by declaring the fragment in the activity's layout file, as
     a <fragment> element
   ˃ or from your application code by adding it to an existing ViewGroup
     container.
» MainActivity.java
   ˃ Main Activity that will host the 2 fragments
   ˃ Layout : res/layout/Activity_main.xml


» Frag1.java
   ˃ Fragment 1 class
   ˃ Layout : res/layout/Frag1.xml



» Frag2.java
   ˃ Fragment 2 class.
   ˃ Layout: res/layout/frag2.xml
04   activities - Android
04   activities - Android
04   activities - Android
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

  <fragment
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:name="com.example.fragtest.Frag1"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_weight="45"
  android:id="@+id/frag1">
</fragment>
<fragment

xmlns:android="http://schemas.android.com/apk/res/an
droid"
  android:name="com.example.fragtest.Frag2"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_weight="55"
  android:id="@+id/frag2">
</fragment>

</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

  <TextView
    android:id="@+id/textview01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Frag ONE"
    tools:context=".MainActivity" />

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/textview01"
    android:text="ClickHere"
    tools:context=".MainActivity" />

</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

  <TextView
    android:id="@+id/textview02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Frag TWO"
    tools:context=".MainActivity" />

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/textview02"
    android:text="Click---Here"
    tools:context=".MainActivity" />
</RelativeLayout>
package com.example.fragtest;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
    }
}
package com.example.fragtest;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Frag1 extends Fragment {

public Frag1() {
// TODO Auto-generated constructor stub
}

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
    View view = inflater.inflate(R.layout.frag1, container, false);
return view;
}

}
package com.example.fragtest;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Frag1 extends Fragment {

public Frag1() {
// TODO Auto-generated constructor stub
}

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
    View view = inflater.inflate(R.layout.frag1, container, false);
return view;
}

}
» What are Fragments?

» What are Fragment Transactions?

» Message passing between two fragments.
  ˃ With example source code.

Contenu connexe

Tendances

android activity
android activityandroid activity
android activityDeepa Rani
 
Android Life Cycle
Android Life CycleAndroid Life Cycle
Android Life Cyclemssaman
 
Android Components & Manifest
Android Components & ManifestAndroid Components & Manifest
Android Components & Manifestma-polimi
 
View groups containers
View groups containersView groups containers
View groups containersMani Selvaraj
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestateOsahon Gino Ediagbonya
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Androidma-polimi
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesAhsanul Karim
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfacesC.o. Nieto
 
Android studio
Android studioAndroid studio
Android studioAndri Yabu
 
Android life cycle
Android life cycleAndroid life cycle
Android life cycle瑋琮 林
 

Tendances (18)

android activity
android activityandroid activity
android activity
 
Android Life Cycle
Android Life CycleAndroid Life Cycle
Android Life Cycle
 
Android Components & Manifest
Android Components & ManifestAndroid Components & Manifest
Android Components & Manifest
 
Android Basics
Android BasicsAndroid Basics
Android Basics
 
Android Components
Android ComponentsAndroid Components
Android Components
 
View groups containers
View groups containersView groups containers
View groups containers
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Android
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
 
Android components
Android componentsAndroid components
Android components
 
android layouts
android layoutsandroid layouts
android layouts
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfaces
 
Android studio
Android studioAndroid studio
Android studio
 
Android session 2
Android session 2Android session 2
Android session 2
 
Activity
ActivityActivity
Activity
 
Android session 3
Android session 3Android session 3
Android session 3
 
Android session 1
Android session 1Android session 1
Android session 1
 
Android life cycle
Android life cycleAndroid life cycle
Android life cycle
 

En vedette

Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Class 02 - Android Study Jams: Android Development for Beginners
Class 02 - Android Study Jams: Android Development for BeginnersClass 02 - Android Study Jams: Android Development for Beginners
Class 02 - Android Study Jams: Android Development for BeginnersJordan Silva
 
02 hello world - Android
02   hello world - Android02   hello world - Android
02 hello world - AndroidWingston
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)TECOS
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and ActivityNikmesoft Ltd
 
Android Activity Transition(ShareElement)
Android Activity Transition(ShareElement)Android Activity Transition(ShareElement)
Android Activity Transition(ShareElement)Ted Liang
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
Http Caching for the Android Aficionado
Http Caching for the Android AficionadoHttp Caching for the Android Aficionado
Http Caching for the Android AficionadoPaul Blundell
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Androidma-polimi
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversCodeAndroid
 
Introduction to Android Studio
Introduction to Android StudioIntroduction to Android Studio
Introduction to Android StudioMichael Pan
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - IntentDaniela Da Cruz
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android StudioSuyash Srijan
 

En vedette (20)

Android activity
Android activityAndroid activity
Android activity
 
Class 02 - Android Study Jams: Android Development for Beginners
Class 02 - Android Study Jams: Android Development for BeginnersClass 02 - Android Study Jams: Android Development for Beginners
Class 02 - Android Study Jams: Android Development for Beginners
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
02 hello world - Android
02   hello world - Android02   hello world - Android
02 hello world - Android
 
The android activity lifecycle
The android activity lifecycleThe android activity lifecycle
The android activity lifecycle
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)
 
Android intent
Android intentAndroid intent
Android intent
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and Activity
 
Android Activity Transition(ShareElement)
Android Activity Transition(ShareElement)Android Activity Transition(ShareElement)
Android Activity Transition(ShareElement)
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
Android Lesson 2
Android Lesson 2Android Lesson 2
Android Lesson 2
 
Http Caching for the Android Aficionado
Http Caching for the Android AficionadoHttp Caching for the Android Aficionado
Http Caching for the Android Aficionado
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
 
Android - Android Intent Types
Android - Android Intent TypesAndroid - Android Intent Types
Android - Android Intent Types
 
Introduction to Android Studio
Introduction to Android StudioIntroduction to Android Studio
Introduction to Android Studio
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - Intent
 
Android studio 2.0
Android studio 2.0Android studio 2.0
Android studio 2.0
 
Android studio
Android studioAndroid studio
Android studio
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
 

Similaire à 04 activities - Android

Android app development basics
Android app development basicsAndroid app development basics
Android app development basicsAnton Narusberg
 
STYLISH FLOOR
STYLISH FLOORSTYLISH FLOOR
STYLISH FLOORABU HASAN
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivitiesmaamir farooq
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activitiesmaamir farooq
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)Oum Saokosal
 
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...olrandir
 
Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.Mohammad Shaker
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in AndroidRobert Cooper
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentMonir Zzaman
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2DHIRAJ PRAVIN
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversUtkarsh Mankad
 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 

Similaire à 04 activities - Android (20)

Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
 
Mini curso Android
Mini curso AndroidMini curso Android
Mini curso Android
 
STYLISH FLOOR
STYLISH FLOORSTYLISH FLOOR
STYLISH FLOOR
 
Android 3
Android 3Android 3
Android 3
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
 
Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Fragment
Fragment Fragment
Fragment
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 

Plus de Wingston

OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012Wingston
 
05 content providers - Android
05   content providers - Android05   content providers - Android
05 content providers - AndroidWingston
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - AndroidWingston
 
01 introduction & setup - Android
01   introduction & setup - Android01   introduction & setup - Android
01 introduction & setup - AndroidWingston
 
OpenCV with android
OpenCV with androidOpenCV with android
OpenCV with androidWingston
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDLWingston
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - PointersWingston
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
Linux – an introduction
Linux – an introductionLinux – an introduction
Linux – an introductionWingston
 
Embedded linux
Embedded linuxEmbedded linux
Embedded linuxWingston
 
04 Arduino Peripheral Interfacing
04   Arduino Peripheral Interfacing04   Arduino Peripheral Interfacing
04 Arduino Peripheral InterfacingWingston
 
03 analogue anrduino fundamentals
03   analogue anrduino fundamentals03   analogue anrduino fundamentals
03 analogue anrduino fundamentalsWingston
 
02 General Purpose Input - Output on the Arduino
02   General Purpose Input -  Output on the Arduino02   General Purpose Input -  Output on the Arduino
02 General Purpose Input - Output on the ArduinoWingston
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the ArduinoWingston
 
4.content mgmt
4.content mgmt4.content mgmt
4.content mgmtWingston
 
8 Web Practices for Drupal
8  Web Practices for Drupal8  Web Practices for Drupal
8 Web Practices for DrupalWingston
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in DrupalWingston
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for DrupalWingston
 
5 User Mgmt in Drupal
5 User Mgmt in Drupal5 User Mgmt in Drupal
5 User Mgmt in DrupalWingston
 

Plus de Wingston (20)

OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012
 
05 content providers - Android
05   content providers - Android05   content providers - Android
05 content providers - Android
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - Android
 
01 introduction & setup - Android
01   introduction & setup - Android01   introduction & setup - Android
01 introduction & setup - Android
 
OpenCV with android
OpenCV with androidOpenCV with android
OpenCV with android
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Linux – an introduction
Linux – an introductionLinux – an introduction
Linux – an introduction
 
Embedded linux
Embedded linuxEmbedded linux
Embedded linux
 
04 Arduino Peripheral Interfacing
04   Arduino Peripheral Interfacing04   Arduino Peripheral Interfacing
04 Arduino Peripheral Interfacing
 
03 analogue anrduino fundamentals
03   analogue anrduino fundamentals03   analogue anrduino fundamentals
03 analogue anrduino fundamentals
 
02 General Purpose Input - Output on the Arduino
02   General Purpose Input -  Output on the Arduino02   General Purpose Input -  Output on the Arduino
02 General Purpose Input - Output on the Arduino
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
 
4.content mgmt
4.content mgmt4.content mgmt
4.content mgmt
 
8 Web Practices for Drupal
8  Web Practices for Drupal8  Web Practices for Drupal
8 Web Practices for Drupal
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in Drupal
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for Drupal
 
5 User Mgmt in Drupal
5 User Mgmt in Drupal5 User Mgmt in Drupal
5 User Mgmt in Drupal
 

Dernier

NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?SANGHEE SHIN
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServiceRenan Moreira de Oliveira
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.francesco barbera
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxYounusS2
 

Dernier (20)

NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptx
 

04 activities - Android

  • 2. » An activity is the equivalent of a Frame/Window in GUI toolkits. It takes up the entire drawable area of the screen (minus the status and title bars on top). » Activities are meant to display the UI and get input from the user. » Activities can be frozen when the focus is switched away from them (eg: incoming phone call). » Services on the other hand keep running for the duration of the user’s ‘session’ on the device.
  • 3. » Any screen state is called an activity. » An Application always starts with a main activity » An application can have multiple activities that the user moves in and out of. » A stack of activities is maintained by the android system to handle back presses and returns.
  • 4. » In res/layout we’ll need to make 2 xml files each defining the layout for the individual activity. ˃ main.xml ˃ second.xml » Each activity needs an activity class associated with it, these are present in the /src folder ˃ mainActivity.java -> main.xml ˃ secondActivity.java -> second.xml
  • 5. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="I&apos;m screen 1 (main.xml)" android:textAppearance="?android:attr/textAppearanceLarge" /> <Button android:id="@+id/button1" android:layout_width="fill_parent" Button that we’ll android:layout_height="wrap_content" use to move to the android:text="Click me to another screen" /> next activity </LinearLayout>
  • 6. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="I&apos;m screen 2 (second.xml)" android:textAppearance="?android:attr/textAppearanceLarge" /> </LinearLayout>
  • 7. package com.wingie; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class mainactivity extends Activity { Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
  • 8. setContentView(R.layout.main); addListenerOnButton(); } public void addListenerOnButton() { final Context context = this; button = (Button) findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(context, second.class); startActivity(intent); } }); Then we create an } intent to move to the next activity, } (Second.java)
  • 10. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wingie" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="13"/> <application android:label="@string/app_name"> <activity android:name=".main" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity This describes the second activity in android:label="@string/app_name" the application android:name=".second" > </activity> </application> </manifest>
  • 11. The super.fn() makes sure that the overridden method is also called before any of our code runs.. public class ExampleActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { The activity is being created. super.onCreate(savedInstanceState); } @Override protected void onStart() { The activity is about to become visible. super.onStart(); } @Override protected void onResume() { The activity has become visible (it is now "resumed"). super.onResume(); }
  • 12. @Override Another activity is taking protected void onPause() { focus (this activity is about super.onPause(); to be "paused"). } @Override protected void onStop() { super.onStop(); The activity is no longer } visible (it is now "stopped") @Override protected void onDestroy() { super.onDestroy(); The activity is about to be } destroyed. }
  • 14. » A Fragment represents a behavior or a portion of user interface in an Activity. » A fragment must always be embedded in an activity ˃ fragment's lifecycle is directly affected by the host activity's lifecycle. » You can insert a fragment into your activity layout ˃ by declaring the fragment in the activity's layout file, as a <fragment> element ˃ or from your application code by adding it to an existing ViewGroup container.
  • 15. » MainActivity.java ˃ Main Activity that will host the 2 fragments ˃ Layout : res/layout/Activity_main.xml » Frag1.java ˃ Fragment 1 class ˃ Layout : res/layout/Frag1.xml » Frag2.java ˃ Fragment 2 class. ˃ Layout: res/layout/frag2.xml
  • 19. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:name="com.example.fragtest.Frag1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="45" android:id="@+id/frag1"> </fragment>
  • 20. <fragment xmlns:android="http://schemas.android.com/apk/res/an droid" android:name="com.example.fragtest.Frag2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="55" android:id="@+id/frag2"> </fragment> </LinearLayout>
  • 21. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textview01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="Frag ONE" tools:context=".MainActivity" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/textview01" android:text="ClickHere" tools:context=".MainActivity" /> </RelativeLayout>
  • 22. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textview02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="Frag TWO" tools:context=".MainActivity" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/textview02" android:text="Click---Here" tools:context=".MainActivity" /> </RelativeLayout>
  • 23. package com.example.fragtest; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
  • 24. package com.example.fragtest; import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Frag1 extends Fragment { public Frag1() { // TODO Auto-generated constructor stub } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.frag1, container, false); return view; } }
  • 25. package com.example.fragtest; import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Frag1 extends Fragment { public Frag1() { // TODO Auto-generated constructor stub } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.frag1, container, false); return view; } }
  • 26. » What are Fragments? » What are Fragment Transactions? » Message passing between two fragments. ˃ With example source code.