SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Introduction to Android
     Development
WHO WE ARE

Eugeniu Arbuleac                          Andrei Catinean
@arbuleac                                             @electryc
arbuleac.ev@gmail.com                andrei.catinean@gmail.com
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): onStart
 D/MyActivity( 1146): onResume




Open another activity, then Back button
 D/MyActivity(   1146):   onClickAnotherActivity
 D/MyActivity(   1146):   onPause
 D/MyActivity(   1146):   onStop
 D/MyActivity(   1146):   onRestart
 D/MyActivity(   1146):   onStart
 D/MyActivity(   1146):   onResume
Activity Lifecycle
Rotate screen
D/MyActivity(   1146):   onPause
D/MyActivity(   1146):   onStop
D/MyActivity(   1146):   onDestroy
D/MyActivity(   1146):   onCreate
D/MyActivity(   1146):   onStart
D/MyActivity(   1146):   onResume
Activity Lifecycle
Rotate screen
D/MyActivity(   1146):   onPause
D/MyActivity(   1146):   onStop
D/MyActivity(   1146):   onDestroy
D/MyActivity(   1146):   onCreate
D/MyActivity(   1146):   onStart
D/MyActivity(   1146):   onResume




Home Button
D/MyActivity( 1146): onPause
D/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

Contenu connexe

Tendances

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
 
Build Widgets
Build WidgetsBuild Widgets
Build Widgetsscottw
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose worldFabio Collini
 
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
 
Implementing cast in android
Implementing cast in androidImplementing cast in android
Implementing cast in androidAngelo Rüggeberg
 
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
 
Testing Android apps based on Dagger and RxJava
Testing Android apps based on Dagger and RxJavaTesting Android apps based on Dagger and RxJava
Testing Android apps based on Dagger and RxJavaFabio Collini
 
State management in android applications
State management in android applicationsState management in android applications
State management in android applicationsGabor Varadi
 
Managing parallelism using coroutines
Managing parallelism using coroutinesManaging parallelism using coroutines
Managing parallelism using coroutinesFabio Collini
 
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
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Ontico
 
Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Kirill Rozov
 

Tendances (20)

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
 
Eddystone beacons demo
Eddystone beacons demoEddystone beacons demo
Eddystone beacons demo
 
Build Widgets
Build WidgetsBuild Widgets
Build Widgets
 
Android wear (coding)
Android wear (coding)Android wear (coding)
Android wear (coding)
 
guice-servlet
guice-servletguice-servlet
guice-servlet
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose world
 
yagdao-0.3.1 JPA guide
yagdao-0.3.1 JPA guideyagdao-0.3.1 JPA guide
yagdao-0.3.1 JPA guide
 
Implementing cast in android
Implementing cast in androidImplementing cast in android
Implementing cast in android
 
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)
 
Testing Android apps based on Dagger and RxJava
Testing Android apps based on Dagger and RxJavaTesting Android apps based on Dagger and RxJava
Testing Android apps based on Dagger and RxJava
 
Exercises
ExercisesExercises
Exercises
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
State management in android applications
State management in android applicationsState management in android applications
State management in android applications
 
Managing parallelism using coroutines
Managing parallelism using coroutinesManaging parallelism using coroutines
Managing parallelism using coroutines
 
Activities
ActivitiesActivities
Activities
 
9 services
9 services9 services
9 services
 
yagdao-0.3.1 hibernate guide
yagdao-0.3.1 hibernate guideyagdao-0.3.1 hibernate guide
yagdao-0.3.1 hibernate guide
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
 
Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2
 
React hooks
React hooksReact hooks
React hooks
 

Similaire à Introduction toandroid

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
 
Android应用开发简介
Android应用开发简介Android应用开发简介
Android应用开发简介easychen
 
Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Alfredo Morresi
 
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
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - AndroidWingston
 
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
 
STYLISH FLOOR
STYLISH FLOORSTYLISH FLOOR
STYLISH FLOORABU HASAN
 
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
 
Advancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and GesturesAdvancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and GesturesSamsung Developers
 
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
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureAlexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureC.T.Co
 

Similaire à Introduction toandroid (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应用开发简介
Android应用开发简介Android应用开发简介
Android应用开发简介
 
Android 3
Android 3Android 3
Android 3
 
Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)Slightly Advanced Android Wear ;)
Slightly Advanced Android Wear ;)
 
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
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
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
 
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
 
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)
 
Advancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and GesturesAdvancing the UI — Part 1: Look, Motion, and Gestures
Advancing the UI — Part 1: Look, Motion, and Gestures
 
Android wearpp
Android wearppAndroid wearpp
Android wearpp
 
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.
 
Android101
Android101Android101
Android101
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 

Introduction toandroid

  • 2. WHO WE ARE Eugeniu Arbuleac Andrei Catinean @arbuleac @electryc arbuleac.ev@gmail.com andrei.catinean@gmail.com
  • 3. Activities and UI Intents Broadcast Receivers Services
  • 5. Activities and UI A screen Application = Σ activity
  • 7. Activity Lifecycle Managed by ActivityManager
  • 8. Activity Lifecycle $ ¢ Managed by ActivityManager Developer says what happens at each state
  • 9. Activity Lifecycle First time run D/MyActivity( 1146): onCreate D/MyActivity( 1146): onStart D/MyActivity( 1146): onResume Open another activity, then Back button D/MyActivity( 1146): onClickAnotherActivity D/MyActivity( 1146): onPause D/MyActivity( 1146): onStop D/MyActivity( 1146): onRestart D/MyActivity( 1146): onStart D/MyActivity( 1146): onResume
  • 10. Activity Lifecycle Rotate screen D/MyActivity( 1146): onPause D/MyActivity( 1146): onStop D/MyActivity( 1146): onDestroy D/MyActivity( 1146): onCreate D/MyActivity( 1146): onStart D/MyActivity( 1146): onResume
  • 11. Activity Lifecycle Rotate screen D/MyActivity( 1146): onPause D/MyActivity( 1146): onStop D/MyActivity( 1146): onDestroy D/MyActivity( 1146): onCreate D/MyActivity( 1146): onStart D/MyActivity( 1146): onResume Home Button D/MyActivity( 1146): onPause D/MyActivity( 1146): onStop
  • 12. 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"); }
  • 13. @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"); } }
  • 14. Declaring the Activity Let your application know about your Activity into the AndroidManifest.xml <manifest ... > <application ... > <activity android:name=".MyActivity" /> ... </application ... > ... </manifest >
  • 15. 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 >
  • 16. Building Android UI XML Declare UI in XML Inflate XML in Java files
  • 17. Building Android UI XML Programmatically Declare UI in XML VS. Initialize new widgets Inflate XML in Java files Customize properties for each
  • 18. 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
  • 19. Layouts and views hierarchy
  • 21. Intents Used to start activities, start/stop services, or send broadcasts
  • 22. Using Intents startActivity(Intent activity); startService(Intent service); stopService(Intent service); sendBroadcast(Intent intent);
  • 23. Explicit Intents startActivity(new Intent(this, TargetActivity.class)); startService(new Intent(this, TargetService.class));
  • 24. 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"));
  • 25. 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>
  • 26. Intent Filters Activity Action Service Receiver
  • 27. Intent Filters Activity Action Service Receiver AndroidManifeset.xml <intent-filter> <action android:name="any.action.you.want" /> </intent-filter>
  • 29. Services Run in background Don’t have UI Run on the UI thread
  • 30. Services Run in background UI Activity Don’t have UI startService(); stopService(); Run on the UI thread Service
  • 31. 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.
  • 32. 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"); } }
  • 33. 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>
  • 35. Broadcast Receivers Intent based publish-subscribe mechanism Listening system events: incoming calls, SMS messages a.o.
  • 36. 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
  • 37. 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() ); } }
  • 38. 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>
  • 39. 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); }
  • 41. THANK YOU Eugeniu Arbuleac Andrei Catinean @arbuleac @electryc arbuleac.ev@gmail.com andrei.catinean@gmail.com