SlideShare a Scribd company logo
1 of 44
WHO WE ARE

Eugeniu Arbuleac                          Andrei Catinean
@arbuleac                                            @electryc
arbuleac.ev@gmail.com                andrei.catinean@gmail.com
Activities and UI
Activities and UI
                    Intents
Activities and UI
                     Intents




          Services
Activities and UI
                                 Intents


Broadcast Receivers

                      Services
Activities and UI
Activities and UI



                    A screen

                    Application = Σ activity
Activity Lifecycle
Activity Lifecycle



                     Managed by ActivityManager
Activity Lifecycle


         $

     ¢               Managed by ActivityManager

               Developer says what happens at each state
Activity Lifecycle
First time run
D/MyActivity( 1146): onCreate
D/MyActivity( 1146):
onStartD/MyActivity( 1146):
onResume




 Open another activity, then Back button

D/MyActivity( 1146):
onClickAnotherActivityD/MyActivity( 1146):
onPauseD/MyActivity( 1146):
onStopD/MyActivity( 1146):
onRestartD/MyActivity( 1146):
onStartD/MyActivity( 1146): onResume
Activity Lifecycle
Rotate screen

D/MyActivity( 1146):
onPauseD/MyActivity( 1146):
onStopD/MyActivity( 1146):
onDestroyD/MyActivity( 1146):
onCreateD/MyActivity( 1146):
onStartD/MyActivity( 1146): onResume
Activity Lifecycle
Rotate screen

D/MyActivity( 1146):
onPauseD/MyActivity( 1146):
onStopD/MyActivity( 1146):
onDestroyD/MyActivity( 1146):
onCreateD/MyActivity( 1146):
onStartD/MyActivity( 1146): onResume




Home Button
D/MyActivity( 1146):
onPauseD/MyActivity( 1146):
onStop
Activity Lifecycle
        package ro.gdgcluj.demoapp;

        import android.app.Activity;
        import android.os.Bundle;
        import android.util.Log;

        public class MyActivity extends Activity {

           static final String TAG = MyActivity.class.getSimpleName();

           @Override
           protected void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               setContentView(R.layout.activity_my);
               Log.d(TAG, "onCreate");
           }

           @Override
           protected void onStart() {
               super.onStart();
               Log.d(TAG, "onStart");
           }

           @Override
           protected void onResume() {
               super.onResume();
               Log.d(TAG, "onResume");
           }
@Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG, "onPause");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d(TAG, "onRestart");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG, "onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy");
    }

}
Declaring the Activity
Let your application know about your Activity into the AndroidManifest.xml

  <manifest ... >
    <application ... >
        <activity android:name=".MyActivity" />
        ...
    </application ... >
    ...
  </manifest >
Declaring the Activity
Let your application know about your Activity into the AndroidManifest.xml

  <manifest ... >
    <application ... >
        <activity android:name=".MyActivity" />
        ...
    </application ... >
    ...
  </manifest >



For your main activity use Intent Filters
 <manifest ... >
   <application ... >
       <activity android:name=".MyActivity" >
           <intent-filter>
                  <action android:name= "android.intent.action.MAIN" />
                  <category android:name= "android.intent.category.LAUNCHER" />
           <intent-filter />
       <activity />
   </application ... >
   ...
 </manifest >
Building Android UI

 XML

  Declare UI in XML

  Inflate XML in Java files
Building Android UI

 XML                                          Programmatically

  Declare UI in XML           VS.           Initialize new widgets

  Inflate XML in Java files         Customize properties for each
Building Android UI

 XML                                          Programmatically

  Declare UI in XML           VS.           Initialize new widgets

  Inflate XML in Java files         Customize properties for each


                          Use them both
Layouts and views hierarchy
Intents
Intents




  Used to start activities, start/stop services, or send broadcasts
Using Intents
startActivity(Intent activity);


startService(Intent service);


stopService(Intent service);


sendBroadcast(Intent intent);
Explicit Intents
startActivity(new Intent(this, TargetActivity.class));

startService(new Intent(this, TargetService.class));
Explicit Intents
startActivity(new Intent(this, TargetActivity.class));

startService(new Intent(this, TargetService.class));




Implicit Intents
startService(new Intent("example.intent.action.IntentService"));

sendBroadcast(new Intent("example.intent.action.Receiver"));
Explicit Intents
startActivity(new Intent(this, TargetActivity.class));

startService(new Intent(this, TargetService.class));




Implicit Intents
startService(new Intent("example.intent.action.IntentService"));

sendBroadcast(new Intent("example.intent.action.Receiver"));




AndroidManifest.xml
<service android:name=".IntentService">
  <intent-filter>
    <action android:name="example.intent.action.IntentService" />
  </intent-filter>
</service>

<receiver android:name=".Receiver">
  <intent-filter>
    <action android:name="example.intent.action.Receiver" />
  </intent-filter>
</receiver>
Intent Filters
                    Activity

           Action   Service

                    Receiver
Intent Filters
                                                      Activity

                               Action                 Service

                                                      Receiver

  AndroidManifeset.xml
  <intent-filter>
      <action android:name="any.action.you.want" />
  </intent-filter>
Services
Services

  Run in background

  Don’t have UI

  Run on the UI thread
Services

  Run in background                  UI Activity

  Don’t have UI          startService();         stopService();




  Run on the UI thread                 Service
Service Lifecycle
              Service starts and "runs" until it
              gets a request to stop



              To offload work from main thread, use intent
              service.


               Intent service uses worker thread,
               stops when done with work.
Service Example
        package ro.gdgcluj.demoapp;

        import   android.app.Service;
        import   android.content.Intent;
        import   android.os.IBinder;
        import   android.util.Log;

        public class MyService extends Service {
          static final String TAG = MyService.class.getSimpleName();

            @Override
            public IBinder onBind(Intent arg0) {
              return null;
            }

            @Override
            public void onCreate() {
              Log.d(TAG, "onCreate");
            }

            @Override
            public int onStartCommand(Intent intent, int flags, int startId) {
              Log.d(TAG, "onStartCommand");
              return START_STICKY;
            }

            @Override
            public void onDestroy() {
              Log.d(TAG, "onDestroy");
            }

        }
Declaring the Service
   Called via its class name

   <service android:name=".ServiceDemo"></service>




   Called via action
   <service android:name=".IntentService">
     <intent-filter>
       <action android:name="example.intent.action.IntentService" />
     </intent-filter>
   </service>
Broadcast Receivers
Broadcast Receivers
     Intent based publish-subscribe mechanism

   Listening system events: incoming calls, SMS messages a.o.
Broadcast Receivers
     Intent based publish-subscribe mechanism

   Listening system events: incoming calls, SMS messages a.o.

                Register for certain intents




             Get notified when intent happens
Broadcast Receiver Example

        package ro.gdgcluj.demoapp;

        import   android.content.BroadcastReceiver;
        import   android.content.Context;
        import   android.content.Intent;
        import   android.util.Log;

        public class Receiver extends BroadcastReceiver {
          static final String TAG = Receiver.class.getSimpleName();

            @Override
            public void onReceive(Context context, Intent intent) {
              Log.d(TAG, "onReceive action: "+intent.getAction() );
            }

        }
Registering the Broadcast Receiver

  Declaring it in AndroidManifest.xml
  <receiver android:name=".ReceiverDemo">
    <intent-filter>
      <action android:name="example.intent.action.Receiver" />
    </intent-filter>
  </receiver>
Registering the Broadcast Receiver
  Registering Programmatically
   @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     ...
     // Create the receiver
     receiver = new Receiver();
     filter = new IntentFilter( ANY_INTENT_ACTION );
   }

   protected void onResume() {
     super.onResume();
     super.registerReceiver(receiver, filter);
   }

   @Override
   protected void onPause() {
     super.onPause();
     unregisterReceiver(receiver);
   }
That’s all!

Questions
THANK YOU

Eugeniu Arbuleac                         Andrei Catinean
@arbuleac                                           @electryc
arbuleac.ev@gmail.com               andrei.catinean@gmail.com

More Related Content

What's hot

Build Widgets
Build WidgetsBuild Widgets
Build Widgetsscottw
 
That’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your BatteryThat’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your BatteryMichael Galpin
 
What's new in Android O
What's new in Android OWhat's new in Android O
What's new in Android OKirill Rozov
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversCodeAndroid
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTDavid Chandler
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleMathias Seguy
 
yagdao-0.3.1 JPA guide
yagdao-0.3.1 JPA guideyagdao-0.3.1 JPA guide
yagdao-0.3.1 JPA guideMert Can Akkan
 
yagdao-0.3.1 hibernate guide
yagdao-0.3.1 hibernate guideyagdao-0.3.1 hibernate guide
yagdao-0.3.1 hibernate guideMert Can Akkan
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinNida Ismail Shah
 
Testing Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UKTesting Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UKFabio Collini
 
Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.Nida Ismail Shah
 
Saindo da zona de conforto… resolvi aprender android
Saindo da zona de conforto… resolvi aprender androidSaindo da zona de conforto… resolvi aprender android
Saindo da zona de conforto… resolvi aprender androidDaniel Baccin
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose worldFabio Collini
 

What's hot (20)

Build Widgets
Build WidgetsBuild Widgets
Build Widgets
 
That’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your BatteryThat’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your Battery
 
React lecture
React lectureReact lecture
React lecture
 
What's new in Android O
What's new in Android OWhat's new in Android O
What's new in Android O
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
 
An intro to cqrs
An intro to cqrsAn intro to cqrs
An intro to cqrs
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
 
yagdao-0.3.1 JPA guide
yagdao-0.3.1 JPA guideyagdao-0.3.1 JPA guide
yagdao-0.3.1 JPA guide
 
Open sourcing the store
Open sourcing the storeOpen sourcing the store
Open sourcing the store
 
yagdao-0.3.1 hibernate guide
yagdao-0.3.1 hibernate guideyagdao-0.3.1 hibernate guide
yagdao-0.3.1 hibernate guide
 
Exercises
ExercisesExercises
Exercises
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
 
Testing Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UKTesting Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UK
 
Activities
ActivitiesActivities
Activities
 
Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.Events: The Object Oriented Hook System.
Events: The Object Oriented Hook System.
 
Saindo da zona de conforto… resolvi aprender android
Saindo da zona de conforto… resolvi aprender androidSaindo da zona de conforto… resolvi aprender android
Saindo da zona de conforto… resolvi aprender android
 
guice-servlet
guice-servletguice-servlet
guice-servlet
 
React hooks
React hooksReact hooks
React hooks
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose world
 

Similar to Introduction to android

Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basicsAnton Narusberg
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - AndroidWingston
 
Android应用开发简介
Android应用开发简介Android应用开发简介
Android应用开发简介easychen
 
Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Alfredo Morresi
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developersPavel Lahoda
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon Berlin
 
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
 
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
 
STYLISH FLOOR
STYLISH FLOORSTYLISH FLOOR
STYLISH FLOORABU HASAN
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsAleksandar Ilić
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsPSTechSerbia
 
[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutesGlobant
 
Androidaop 170105090257
Androidaop 170105090257Androidaop 170105090257
Androidaop 170105090257newegg
 

Similar to Introduction to android (20)

Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
 
Android 3
Android 3Android 3
Android 3
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
Android应用开发简介
Android应用开发简介Android应用开发简介
Android应用开发简介
 
Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 
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)
 
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 Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
STYLISH FLOOR
STYLISH FLOORSTYLISH FLOOR
STYLISH FLOOR
 
Ruby conf2012
Ruby conf2012Ruby conf2012
Ruby conf2012
 
Android開発の基礎_20101218
Android開発の基礎_20101218Android開発の基礎_20101218
Android開発の基礎_20101218
 
Android wearpp
Android wearppAndroid wearpp
Android wearpp
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
 
[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes[AngularJS] From Angular to Mobile in 30 minutes
[AngularJS] From Angular to Mobile in 30 minutes
 
Android101
Android101Android101
Android101
 
Androidaop 170105090257
Androidaop 170105090257Androidaop 170105090257
Androidaop 170105090257
 

Recently uploaded

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

Introduction to android

  • 1.
  • 2. WHO WE ARE Eugeniu Arbuleac Andrei Catinean @arbuleac @electryc arbuleac.ev@gmail.com andrei.catinean@gmail.com
  • 5. Activities and UI Intents Services
  • 6. Activities and UI Intents Broadcast Receivers Services
  • 8. Activities and UI A screen Application = Σ activity
  • 10. Activity Lifecycle Managed by ActivityManager
  • 11. Activity Lifecycle $ ¢ Managed by ActivityManager Developer says what happens at each state
  • 12. Activity Lifecycle First time run D/MyActivity( 1146): onCreate D/MyActivity( 1146): onStartD/MyActivity( 1146): onResume Open another activity, then Back button D/MyActivity( 1146): onClickAnotherActivityD/MyActivity( 1146): onPauseD/MyActivity( 1146): onStopD/MyActivity( 1146): onRestartD/MyActivity( 1146): onStartD/MyActivity( 1146): onResume
  • 13. Activity Lifecycle Rotate screen D/MyActivity( 1146): onPauseD/MyActivity( 1146): onStopD/MyActivity( 1146): onDestroyD/MyActivity( 1146): onCreateD/MyActivity( 1146): onStartD/MyActivity( 1146): onResume
  • 14. Activity Lifecycle Rotate screen D/MyActivity( 1146): onPauseD/MyActivity( 1146): onStopD/MyActivity( 1146): onDestroyD/MyActivity( 1146): onCreateD/MyActivity( 1146): onStartD/MyActivity( 1146): onResume Home Button D/MyActivity( 1146): onPauseD/MyActivity( 1146): onStop
  • 15. Activity Lifecycle package ro.gdgcluj.demoapp; import android.app.Activity; import android.os.Bundle; import android.util.Log; public class MyActivity extends Activity { static final String TAG = MyActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); Log.d(TAG, "onCreate"); } @Override protected void onStart() { super.onStart(); Log.d(TAG, "onStart"); } @Override protected void onResume() { super.onResume(); Log.d(TAG, "onResume"); }
  • 16. @Override protected void onPause() { super.onPause(); Log.d(TAG, "onPause"); } @Override protected void onRestart() { super.onRestart(); Log.d(TAG, "onRestart"); } @Override protected void onStop() { super.onStop(); Log.d(TAG, "onStop"); } @Override protected void onDestroy() { super.onDestroy(); Log.d(TAG, "onDestroy"); } }
  • 17. Declaring the Activity Let your application know about your Activity into the AndroidManifest.xml <manifest ... > <application ... > <activity android:name=".MyActivity" /> ... </application ... > ... </manifest >
  • 18. Declaring the Activity Let your application know about your Activity into the AndroidManifest.xml <manifest ... > <application ... > <activity android:name=".MyActivity" /> ... </application ... > ... </manifest > For your main activity use Intent Filters <manifest ... > <application ... > <activity android:name=".MyActivity" > <intent-filter> <action android:name= "android.intent.action.MAIN" /> <category android:name= "android.intent.category.LAUNCHER" /> <intent-filter /> <activity /> </application ... > ... </manifest >
  • 19. Building Android UI XML Declare UI in XML Inflate XML in Java files
  • 20. Building Android UI XML Programmatically Declare UI in XML VS. Initialize new widgets Inflate XML in Java files Customize properties for each
  • 21. Building Android UI XML Programmatically Declare UI in XML VS. Initialize new widgets Inflate XML in Java files Customize properties for each Use them both
  • 22. Layouts and views hierarchy
  • 24. Intents Used to start activities, start/stop services, or send broadcasts
  • 25. Using Intents startActivity(Intent activity); startService(Intent service); stopService(Intent service); sendBroadcast(Intent intent);
  • 26. Explicit Intents startActivity(new Intent(this, TargetActivity.class)); startService(new Intent(this, TargetService.class));
  • 27. Explicit Intents startActivity(new Intent(this, TargetActivity.class)); startService(new Intent(this, TargetService.class)); Implicit Intents startService(new Intent("example.intent.action.IntentService")); sendBroadcast(new Intent("example.intent.action.Receiver"));
  • 28. Explicit Intents startActivity(new Intent(this, TargetActivity.class)); startService(new Intent(this, TargetService.class)); Implicit Intents startService(new Intent("example.intent.action.IntentService")); sendBroadcast(new Intent("example.intent.action.Receiver")); AndroidManifest.xml <service android:name=".IntentService"> <intent-filter> <action android:name="example.intent.action.IntentService" /> </intent-filter> </service> <receiver android:name=".Receiver"> <intent-filter> <action android:name="example.intent.action.Receiver" /> </intent-filter> </receiver>
  • 29. Intent Filters Activity Action Service Receiver
  • 30. Intent Filters Activity Action Service Receiver AndroidManifeset.xml <intent-filter> <action android:name="any.action.you.want" /> </intent-filter>
  • 32. Services Run in background Don’t have UI Run on the UI thread
  • 33. Services Run in background UI Activity Don’t have UI startService(); stopService(); Run on the UI thread Service
  • 34. Service Lifecycle Service starts and "runs" until it gets a request to stop To offload work from main thread, use intent service. Intent service uses worker thread, stops when done with work.
  • 35. Service Example package ro.gdgcluj.demoapp; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; public class MyService extends Service { static final String TAG = MyService.class.getSimpleName(); @Override public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { Log.d(TAG, "onCreate"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "onStartCommand"); return START_STICKY; } @Override public void onDestroy() { Log.d(TAG, "onDestroy"); } }
  • 36. Declaring the Service Called via its class name <service android:name=".ServiceDemo"></service> Called via action <service android:name=".IntentService"> <intent-filter> <action android:name="example.intent.action.IntentService" /> </intent-filter> </service>
  • 38. Broadcast Receivers Intent based publish-subscribe mechanism Listening system events: incoming calls, SMS messages a.o.
  • 39. Broadcast Receivers Intent based publish-subscribe mechanism Listening system events: incoming calls, SMS messages a.o. Register for certain intents Get notified when intent happens
  • 40. Broadcast Receiver Example package ro.gdgcluj.demoapp; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class Receiver extends BroadcastReceiver { static final String TAG = Receiver.class.getSimpleName(); @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "onReceive action: "+intent.getAction() ); } }
  • 41. Registering the Broadcast Receiver Declaring it in AndroidManifest.xml <receiver android:name=".ReceiverDemo"> <intent-filter> <action android:name="example.intent.action.Receiver" /> </intent-filter> </receiver>
  • 42. Registering the Broadcast Receiver Registering Programmatically @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... // Create the receiver receiver = new Receiver(); filter = new IntentFilter( ANY_INTENT_ACTION ); } protected void onResume() { super.onResume(); super.registerReceiver(receiver, filter); } @Override protected void onPause() { super.onPause(); unregisterReceiver(receiver); }
  • 44. THANK YOU Eugeniu Arbuleac Andrei Catinean @arbuleac @electryc arbuleac.ev@gmail.com andrei.catinean@gmail.com