SlideShare une entreprise Scribd logo
1  sur  14
Intents and Broadcast Receivers
l
l
l
l
l

•
•
•
•

Intents

Allows communication between loosely-connected components
Allows for late run-time binding of components
Explicit
Implicit
Intent myIntent = new Intent(AdventDevos.this, Devo.class);
myIntent.putExtra("ButtonNum", ""+index);
startActivity(myIntent);
//finish(); //removes this Activity from the stack

Intent i = new Intent(Intent.ACTION_VIEW,
•
Uri.parse("http://www.biblegateway.com/passage/?search="+
•
passage +"&version=NIV"));
• startActivity(i);
l
l

l
l
l
l
l
l

Other Native Android Actions

ACTION_ANSWER – handle incoming call
ACTION_DIAL – bring up dialer with phone #
ACTION_PICK – pick item (e.g. from contacts)
ACTION_INSERT – add item (e.g. to contacts)
ACTION_SENDTO – send message to contact
ACTION_WEB_SEARCH – search web
l

l
l

l

Sub-Activities

Activities are independent
However, sometimes we want to start an activity that gives
us something back (e.g. select a contact and return the
result)
Use
– startActivityForResult(Intent i, int id)
– instead of
– startActivity(Intent)
l

•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

Capturing Intent Return Results

class ParentActivity extends Activity {
private static final int SUB_CODE = 34;
…
Intent intent = new Intent(…);
startActivityForResult(intent, SUB_CODE);
…
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SUB_CODE)
if (resultCode == Activity.RESULT_OK) {
Uri returnedUri = data.getData();
String returnedString = data.getStringExtra(SOME_CONSTANT,””);
…}
if (resultCode == Activity.RESULT_CANCELED) { … }
}
};
l

•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•

Capturing Intent Return Results

class SubActivity extends Activity {
…
if (/* everything went fine */) {
Uri data = Uri.parse(“content://someuri/”);
Intent result = new Intent(null,data);
result.putStringExtra(SOME_CONSTANT, “This is some data”);
setResult(RESULT_OK, result);
finish();
}
…
if (/* everything did not go fine or the user did not complete the action */) {
setResult(RESULT_CANCELED, null);
finish();
}
…
};
l

Using a Native App Action

• public class MyActivity extends Activity {
•
//from http://developer.android.com/reference/android/app/Activity.html
•
...
•
static final int PICK_CONTACT_REQUEST = 0;
•
protected boolean onKeyDown(int keyCode, KeyEvent event) {
•
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
•
// When the user center presses, let them pick a contact.
•
startActivityForResult(
•
new Intent(Intent.ACTION_PICK, new Uri("content://contacts")),
•
PICK_CONTACT_REQUEST);
•
return true;
•
}
•
return false;
•
}
•
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
•
if (requestCode == PICK_CONTACT_REQUEST) {
•
if (resultCode == RESULT_OK) {
•
// A contact was picked. Here we will just display it to the user.
•
startActivity(new Intent(Intent.ACTION_VIEW, data)); }}
•
}}
l

l
l

l
l

Broadcasts and Broadcast Receivers

So far we have used Intents to start Activities
Intents can also be used to send messages anonymously
between components
Messages are sent with sendBroadcast()
Messages are received by extending the
BroadcastReceiver class
l

Sending a Broadcast

• //…
•
public static final String MAP_ADDED =
•
“com.simexusa.cm.MAP_ADDED”;
• //…
•
Intent intent = new Intent(MAP_ADDED);
•
intent.putStringExtra(“mapname”, “Cal Poly”);
•
sendBroadcast(intent);
• //…

• Typically like a package name to keep it unique
l

Receiving a Broadcast

• public class MapBroadcastReceiver extends BroadcastReceiver {

• Must complete in <5 seconds
•
@Override
•
public void onReceive(Context context, Intent intent) {
•
Uri data = intent.getData();
•
String name = data.getStringExtra(“mapname”);
l
•
//do something
Broadcast Receivers are started automatically – you don’t have to try to
keep an Activity running
•
context.startActivity(…);
•
}
• };
l
l

Registering a BroadcastReceiver

Statically in ApplicationManifest.xml

• <receiver android:name=“.MapBroadcastReceiver”>
• <intent-filter>
•
<action android:name=“com.simexusa.cm.MAP_ADDED”>
• </intent-filter>
•
• </receiver>

• or dynamically in code (e.g. if only needed while
visible)
•
•
•
•
•

IntentFilter filter = new IntentFilter(MAP_ADDED);
MapBroadcastReceiver mbr = new MapBroadcastReceiver();
registerReceiver(mbr, filter);
…
• in onRestart()
unregisterReceiver(mbr);

• in onPause() ?

?
l

l
l
l

Native Broadcasts

ACTION_CAMERA_BUTTON
ACTION_TIMEZONE_CHANGED
ACTION_BOOT_COMPLETED
l requires RECEIVE_BOOT_COMPLETED permission
l
l

l

Intent filters register application components with
Android
Intent filter tags:
l
l
l
l

l

Intent Filters

action – unique identifier of action being serviced
category – circumstances when action should be serviced (e.g.
ALTERNATIVE, DEFAULT, LAUNCHER)
data – type of data that intent can handle
Ex. URI = content://com.example.project:200/folder/subfolder/etc

Components that can handle implicit intents (one’s that
are not explicitly called by name), must declare category
DEFAULT or LAUNCHER
<activity android:name="NotesList" android:label="@string/title_notes_list">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
</intent-filter>
</activity>
<activity android:name="NoteEditor"
android:theme="@android:style/Theme.Light"
android:label="@string/title_note" >
<intent-filter android:label="@string/resolve_edit">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="com.android.notepad.action.EDIT_NOTE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.INSERT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
</intent-filter>

Contenu connexe

Similaire à Intents broadcastreceivers

Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database faiz324545
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart JfokusLars Vogel
 
Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileKonstantin Loginov
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3Edureka!
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptxMugiiiReee
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdfssusere71a07
 
iOS for C# Developers - DevConnections Talk
iOS for C# Developers - DevConnections TalkiOS for C# Developers - DevConnections Talk
iOS for C# Developers - DevConnections TalkMiguel de Icaza
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsSubhransu Behera
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptBirukMarkos
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentOwain Lewis
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptxusvirat1805
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development IntroLuis Azevedo
 
Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidEmanuele Di Saverio
 

Similaire à Intents broadcastreceivers (20)

Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 
App basic
App basicApp basic
App basic
 
Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve Mobile
 
unit3.pptx
unit3.pptxunit3.pptx
unit3.pptx
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
iOS for C# Developers - DevConnections Talk
iOS for C# Developers - DevConnections TalkiOS for C# Developers - DevConnections Talk
iOS for C# Developers - DevConnections Talk
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIs
 
Intents are Awesome
Intents are AwesomeIntents are Awesome
Intents are Awesome
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).ppt
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development Intro
 
Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for Android
 
09events
09events09events
09events
 

Plus de Training Guide (7)

Map
MapMap
Map
 
Persistences
PersistencesPersistences
Persistences
 
Theads services
Theads servicesTheads services
Theads services
 
Application lifecycle
Application lifecycleApplication lifecycle
Application lifecycle
 
Deployment
DeploymentDeployment
Deployment
 
Getting started
Getting startedGetting started
Getting started
 
Tdd
TddTdd
Tdd
 

Dernier

Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentationuneakwhite
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizharallensay1
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture conceptP&CO
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfAdmir Softic
 
Call Girls From Raj Nagar Extension Ghaziabad❤️8448577510 ⊹Best Escorts Servi...
Call Girls From Raj Nagar Extension Ghaziabad❤️8448577510 ⊹Best Escorts Servi...Call Girls From Raj Nagar Extension Ghaziabad❤️8448577510 ⊹Best Escorts Servi...
Call Girls From Raj Nagar Extension Ghaziabad❤️8448577510 ⊹Best Escorts Servi...lizamodels9
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptxnandhinijagan9867
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceDamini Dixit
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxWorkforce Group
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Falcon Invoice Discounting
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon investment
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting
 
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLWhitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLkapoorjyoti4444
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...lizamodels9
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLkapoorjyoti4444
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...Aggregage
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...daisycvs
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876dlhescort
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Sheetaleventcompany
 

Dernier (20)

Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Call Girls From Raj Nagar Extension Ghaziabad❤️8448577510 ⊹Best Escorts Servi...
Call Girls From Raj Nagar Extension Ghaziabad❤️8448577510 ⊹Best Escorts Servi...Call Girls From Raj Nagar Extension Ghaziabad❤️8448577510 ⊹Best Escorts Servi...
Call Girls From Raj Nagar Extension Ghaziabad❤️8448577510 ⊹Best Escorts Servi...
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business Growth
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLWhitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
 

Intents broadcastreceivers

  • 2. l l l l l • • • • Intents Allows communication between loosely-connected components Allows for late run-time binding of components Explicit Implicit Intent myIntent = new Intent(AdventDevos.this, Devo.class); myIntent.putExtra("ButtonNum", ""+index); startActivity(myIntent); //finish(); //removes this Activity from the stack Intent i = new Intent(Intent.ACTION_VIEW, • Uri.parse("http://www.biblegateway.com/passage/?search="+ • passage +"&version=NIV")); • startActivity(i); l
  • 3. l l l l l l l Other Native Android Actions ACTION_ANSWER – handle incoming call ACTION_DIAL – bring up dialer with phone # ACTION_PICK – pick item (e.g. from contacts) ACTION_INSERT – add item (e.g. to contacts) ACTION_SENDTO – send message to contact ACTION_WEB_SEARCH – search web
  • 4. l l l l Sub-Activities Activities are independent However, sometimes we want to start an activity that gives us something back (e.g. select a contact and return the result) Use – startActivityForResult(Intent i, int id) – instead of – startActivity(Intent)
  • 5. l • • • • • • • • • • • • • • • • • Capturing Intent Return Results class ParentActivity extends Activity { private static final int SUB_CODE = 34; … Intent intent = new Intent(…); startActivityForResult(intent, SUB_CODE); … @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == SUB_CODE) if (resultCode == Activity.RESULT_OK) { Uri returnedUri = data.getData(); String returnedString = data.getStringExtra(SOME_CONSTANT,””); …} if (resultCode == Activity.RESULT_CANCELED) { … } } };
  • 6. l • • • • • • • • • • • • • • • • Capturing Intent Return Results class SubActivity extends Activity { … if (/* everything went fine */) { Uri data = Uri.parse(“content://someuri/”); Intent result = new Intent(null,data); result.putStringExtra(SOME_CONSTANT, “This is some data”); setResult(RESULT_OK, result); finish(); } … if (/* everything did not go fine or the user did not complete the action */) { setResult(RESULT_CANCELED, null); finish(); } … };
  • 7. l Using a Native App Action • public class MyActivity extends Activity { • //from http://developer.android.com/reference/android/app/Activity.html • ... • static final int PICK_CONTACT_REQUEST = 0; • protected boolean onKeyDown(int keyCode, KeyEvent event) { • if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { • // When the user center presses, let them pick a contact. • startActivityForResult( • new Intent(Intent.ACTION_PICK, new Uri("content://contacts")), • PICK_CONTACT_REQUEST); • return true; • } • return false; • } • protected void onActivityResult(int requestCode, int resultCode, Intent data) { • if (requestCode == PICK_CONTACT_REQUEST) { • if (resultCode == RESULT_OK) { • // A contact was picked. Here we will just display it to the user. • startActivity(new Intent(Intent.ACTION_VIEW, data)); }} • }}
  • 8. l l l l l Broadcasts and Broadcast Receivers So far we have used Intents to start Activities Intents can also be used to send messages anonymously between components Messages are sent with sendBroadcast() Messages are received by extending the BroadcastReceiver class
  • 9. l Sending a Broadcast • //… • public static final String MAP_ADDED = • “com.simexusa.cm.MAP_ADDED”; • //… • Intent intent = new Intent(MAP_ADDED); • intent.putStringExtra(“mapname”, “Cal Poly”); • sendBroadcast(intent); • //… • Typically like a package name to keep it unique
  • 10. l Receiving a Broadcast • public class MapBroadcastReceiver extends BroadcastReceiver { • Must complete in <5 seconds • @Override • public void onReceive(Context context, Intent intent) { • Uri data = intent.getData(); • String name = data.getStringExtra(“mapname”); l • //do something Broadcast Receivers are started automatically – you don’t have to try to keep an Activity running • context.startActivity(…); • } • };
  • 11. l l Registering a BroadcastReceiver Statically in ApplicationManifest.xml • <receiver android:name=“.MapBroadcastReceiver”> • <intent-filter> • <action android:name=“com.simexusa.cm.MAP_ADDED”> • </intent-filter> • • </receiver> • or dynamically in code (e.g. if only needed while visible) • • • • • IntentFilter filter = new IntentFilter(MAP_ADDED); MapBroadcastReceiver mbr = new MapBroadcastReceiver(); registerReceiver(mbr, filter); … • in onRestart() unregisterReceiver(mbr); • in onPause() ? ?
  • 13. l l l Intent filters register application components with Android Intent filter tags: l l l l l Intent Filters action – unique identifier of action being serviced category – circumstances when action should be serviced (e.g. ALTERNATIVE, DEFAULT, LAUNCHER) data – type of data that intent can handle Ex. URI = content://com.example.project:200/folder/subfolder/etc Components that can handle implicit intents (one’s that are not explicitly called by name), must declare category DEFAULT or LAUNCHER
  • 14. <activity android:name="NotesList" android:label="@string/title_notes_list"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.EDIT" /> <action android:name="android.intent.action.PICK" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.GET_CONTENT" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="vnd.android.cursor.item/vnd.google.note" /> </intent-filter> </activity> <activity android:name="NoteEditor" android:theme="@android:style/Theme.Light" android:label="@string/title_note" > <intent-filter android:label="@string/resolve_edit"> <action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.EDIT" /> <action android:name="com.android.notepad.action.EDIT_NOTE" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="vnd.android.cursor.item/vnd.google.note" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.INSERT" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" /> </intent-filter>