0
Intro to Android
for iOS developers
Chiu-Ki Chan
@chiuki
@chiuki@chiuki
@chiuki@chiuki
Hello World
Layouts
Intents & Components
Hello World
@chiuki
@chiuki
ViewController
@chiuki
@chiuki
@chiuki
xib
@chiuki
@chiuki
@chiuki
@chiuki
@chiuki
IBOutlet
@chiuki
@chiuki@chiuki
Center
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_con...
@chiuki
@chiuki@chiuki
Button
<Button
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_conte...
@chiuki
LinearLayout
@chiuki
@chiuki@chiuki
LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android...
@chiuki@chiuki
IBAction
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gra...
@chiuki@chiuki
IBAction
public class MainActivity extends Activity {
private TextView countView;
private int count = 0;
pr...
@chiuki@chiuki
Update view
public class MainActivity extends Activity {
private TextView countView;
private int count = 0;...
@chiuki
@chiuki
@chiuki
RelativeLayout
@chiuki
@chiuki
@chiuki
@chiuki
@chiuki
<RelativeLayout>
<TextView
android:id="@+id/count"
android:layout_centerInParent="true" />
<Button
android:id="@+i...
@chiuki
<RelativeLayout>
<TextView
android:id="@+id/count"
android:layout_centerInParent="true" />
<Button
android:id="@+i...
@chiuki
<RelativeLayout>
<TextView
android:id="@+id/count"
android:layout_centerInParent="true" />
<Button
android:id="@+i...
@chiuki
<RelativeLayout>
<TextView
android:id="@+id/count"
android:layout_centerInParent="true" />
<Button
android:id="@+i...
@chiuki
<RelativeLayout>
<TextView
android:id="@+id/count"
android:layout_centerInParent="true" />
<Button
android:id="@+i...
@chiuki@chiuki
Device Preview
@chiuki@chiuki
Bigger text on tablets
Resource Folders
@chiuki@chiuki
textSize
<TextView
android:id="@+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_...
@chiuki@chiuki
res/values/dimens.xml
<TextView
android:id="@+id/count"
android:layout_width="wrap_content"
android:layout_...
@chiuki@chiuki
res/values-sw600dp/dimens.xml
<TextView
android:id="@+id/count"
android:layout_width="wrap_content"
android...
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA, ja
Screen si...
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA, ja
Screen si...
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA, ja
Screen si...
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA, ja
Screen si...
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA, ja
Screen si...
Activity Lifecycle
@chiuki@chiuki
onCreate()
Activity Lifecycle
@chiuki@chiuki
onCreate()
Activity Lifecycle
@chiuki@chiuki
onCreate() viewDidLoad:
Activity Lifecycle
@chiuki@chiuki
onCreate() viewDidLoad:
onStart()
Activity Lifecycle
@chiuki@chiuki
onCreate() viewDidLoad:
onStart()
onResume()
Activity Lifecycle
@chiuki@chiuki
onCreate() viewDidLoad:
onStart()
onResume()
viewWillAppear:
viewDidAppear:
Activity Lifecycle
@chiuki@chiuki
onCreate() viewDidLoad:
onStart()
onResume()
viewWillAppear:
viewDidAppear:
onPause()
Activity Lifecycle
@chiuki@chiuki
onCreate() viewDidLoad:
onStart()
onResume()
viewWillAppear:
viewDidAppear:
onPause()
onStop()
Activity Lif...
@chiuki@chiuki
onCreate() viewDidLoad:
onStart()
onResume()
viewWillAppear:
viewDidAppear:
onPause()
onStop()
viewWillDisa...
@chiuki@chiuki
onCreate() viewDidLoad:
onStart()
onResume()
viewWillAppear:
viewDidAppear:
onPause()
onStop()
viewWillDisa...
@chiuki@chiuki
onCreate() viewDidLoad:
onStart()
onResume()
viewWillAppear:
viewDidAppear:
onPause()
onStop()
viewWillDisa...
@chiuki@chiuki
onCreate() viewDidLoad:
onStart()
onResume()
viewWillAppear:
viewDidAppear:
onPause()
onStop()
viewWillDisa...
@chiuki@chiuki
Visibility
More Activities
@chiuki@chiuki
startActivity (explicit)
Intent intent = new Intent(this, NumberActivity.class);
intent.putExtra("count", c...
@chiuki@chiuki
startActivity (explicit)
Intent intent = new Intent(this, NumberActivity.class);
intent.putExtra("count", c...
@chiuki@chiuki
startActivity (explicit)
Intent intent = new Intent(this, NumberActivity.class);
intent.putExtra("count", c...
@chiuki@chiuki
startActivity (implicit)
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://t...
@chiuki@chiuki
startActivity (implicit)
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://t...
@chiuki@chiuki
startActivity (implicit)
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://t...
@chiuki@chiuki
startActivity (implicit)
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://t...
@chiuki@chiuki
Register your Activity
<activity android:name=".YourActivity">
<intent-filter>
   <action android:name="and...
@chiuki@chiuki
IntentFilter: Action
<activity android:name=".YourActivity">
<intent-filter>
   <action android:name="andro...
@chiuki@chiuki
IntentFilter: Data
<activity android:name=".YourActivity">
<intent-filter>
   <action android:name="android...
@chiuki@chiuki
IntentFilter: Category
<activity android:name=".YourActivity">
<intent-filter>
   <action android:name="and...
@chiuki@chiuki
IntentFilter: Category
<activity android:name=".YourActivity">
<intent-filter>
   <action android:name="and...
@chiuki@chiuki
Intent Data
<activity android:name=".YourActivity">
<intent-filter>
   <action android:name="android.intent...
@chiuki@chiuki
startActivityForResult
private static final int REQUEST_CODE_CAMERA = 1;
Intent intent = new Intent(MediaSt...
@chiuki@chiuki
startActivityForResult
private static final int REQUEST_CODE_CAMERA = 1;
Intent intent = new Intent(MediaSt...
@chiuki@chiuki
Providing Result
Intent data = new Intent();
data.putExtra("data", bitmap);
setResult(RESULT_OK, data);
fin...
@chiuki@chiuki
Intent Data
Intent data = new Intent();
data.putExtra("data", bitmap);
setResult(RESULT_OK, data);
finish()...
@chiuki@chiuki
Result Code
Intent data = new Intent();
data.putExtra("data", bitmap);
setResult(RESULT_OK, data);
finish()...
@chiuki@chiuki
Share intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, subject)...
@chiuki@chiuki
IntentFilter: Type
<activity android:name=".YourActivity">
<intent-filter>
   <action android:name="android...
@chiuki@chiuki
Intent Data
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
String message = intent.getString...
Beyond Activities
@chiuki@chiuki
Service BroadcastReceiver
ContentProvider Notification
@chiuki@chiuki
Service
Look ma, no UI!
@chiuki@chiuki
Service
Long-running
@chiuki@chiuki
BroadcastReceiver
Respond
@chiuki@chiuki
BroadcastReceiver
Respond
Battery low
Wifi connected
Incoming SMS
App installed
Screen off
@chiuki@chiuki
ContentProvider
Provide data to other apps
@chiuki@chiuki
ContentProvider
Provide data to other apps
Contacts
Images Music
Calendar
@chiuki@chiuki
ContentProvider
Internal data
(unless you need SQLite interface)
@chiuki@chiuki
Notification
Notify
@chiuki@chiuki
Notify
@chiuki@chiuki
Notification
Communicate with background Service
@chiuki@chiuki
Background Service
Case study
@chiuki
Email Outbox
@chiuki
@chiuki@chiuki
Notification
@chiuki@chiuki
AlarmService
@chiuki@chiuki
Connectivity change
Summary
@chiuki@chiuki
Summary
Hello World
Layouts
Resource Folders
Activity Lifecycle
Intents & Components
Case Study
@chiuki@chiuki
Thank you!
http://eepurl.com/lR5uD
http://blog.sqisland.com
http://twitter.com/chiuki
Upcoming SlideShare
Loading in...5
×

Intro to Android for iOS developers

5,695

Published on

Curious about Android, but never found the time to look into it? Come to this session for an accelerated introduction. We will look at the basic structure of an Android app, then deep dive into two aspects that differentiate Android from iOS: layout and intents. How does the layout system deal with the myriad of Android devices? How do intents facilitate deep integration among Android apps?

Published in: Technology, News & Politics
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,695
On Slideshare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
94
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "Intro to Android for iOS developers"

  1. 1. Intro to Android for iOS developers Chiu-Ki Chan @chiuki
  2. 2. @chiuki@chiuki
  3. 3. @chiuki@chiuki Hello World Layouts Intents & Components
  4. 4. Hello World
  5. 5. @chiuki
  6. 6. @chiuki ViewController
  7. 7. @chiuki
  8. 8. @chiuki
  9. 9. @chiuki xib
  10. 10. @chiuki
  11. 11. @chiuki
  12. 12. @chiuki
  13. 13. @chiuki
  14. 14. @chiuki IBOutlet
  15. 15. @chiuki
  16. 16. @chiuki@chiuki Center <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" />
  17. 17. @chiuki
  18. 18. @chiuki@chiuki Button <Button android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/add" />
  19. 19. @chiuki LinearLayout
  20. 20. @chiuki
  21. 21. @chiuki@chiuki LinearLayout <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > <TextView android:id="@+id/count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="128sp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/add" android:onClick="add" /> </LinearLayout>
  22. 22. @chiuki@chiuki IBAction <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > <TextView android:id="@+id/count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="128sp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/add" android:onClick="add" /> </LinearLayout>
  23. 23. @chiuki@chiuki IBAction public class MainActivity extends Activity { private TextView countView; private int count = 0; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); countView = (TextView) findViewById(R.id.count); updateCount(); } public void add(View v) { count += 1; updateCount(); } private void updateCount() { countView.setText(String.valueOf(count)); } } android:onClick="add"
  24. 24. @chiuki@chiuki Update view public class MainActivity extends Activity { private TextView countView; private int count = 0; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); countView = (TextView) findViewById(R.id.count); updateCount(); } public void add(View v) { count += 1; updateCount(); } private void updateCount() { countView.setText(String.valueOf(count)); } }
  25. 25. @chiuki
  26. 26. @chiuki
  27. 27. @chiuki RelativeLayout
  28. 28. @chiuki
  29. 29. @chiuki
  30. 30. @chiuki
  31. 31. @chiuki
  32. 32. @chiuki <RelativeLayout> <TextView android:id="@+id/count" android:layout_centerInParent="true" /> <Button android:id="@+id/reset" android:layout_below="@id/count" android:layout_centerHorizontal="true" android:text="@string/reset" /> <Button android:layout_below="@id/count" android:layout_toLeftOf="@id/reset" android:text="@string/subtract" /> <Button android:layout_below="@id/count" android:layout_toRightOf="@id/reset" android:text="@string/add" /> </RelativeLayout>
  33. 33. @chiuki <RelativeLayout> <TextView android:id="@+id/count" android:layout_centerInParent="true" /> <Button android:id="@+id/reset" android:layout_below="@id/count" android:layout_centerHorizontal="true" android:text="@string/reset" /> <Button android:layout_below="@id/count" android:layout_toLeftOf="@id/reset" android:text="@string/subtract" /> <Button android:layout_below="@id/count" android:layout_toRightOf="@id/reset" android:text="@string/add" /> </RelativeLayout>
  34. 34. @chiuki <RelativeLayout> <TextView android:id="@+id/count" android:layout_centerInParent="true" /> <Button android:id="@+id/reset" android:layout_below="@id/count" android:layout_centerHorizontal="true" android:text="@string/reset" /> <Button android:layout_below="@id/count" android:layout_toLeftOf="@id/reset" android:text="@string/subtract" /> <Button android:layout_below="@id/count" android:layout_toRightOf="@id/reset" android:text="@string/add" /> </RelativeLayout>
  35. 35. @chiuki <RelativeLayout> <TextView android:id="@+id/count" android:layout_centerInParent="true" /> <Button android:id="@+id/reset" android:layout_below="@id/count" android:layout_centerHorizontal="true" android:text="@string/reset" /> <Button android:layout_toLeftOf="@id/reset" android:text="@string/subtract" /> <Button android:layout_below="@id/count" android:layout_toRightOf="@id/reset" android:text="@string/add" /> </RelativeLayout>
  36. 36. @chiuki <RelativeLayout> <TextView android:id="@+id/count" android:layout_centerInParent="true" /> <Button android:id="@+id/reset" android:layout_below="@id/count" android:layout_centerHorizontal="true" android:text="@string/reset" /> <Button android:layout_below="@id/count" android:layout_toLeftOf="@id/reset" android:text="@string/subtract" /> <Button android:layout_below="@id/count" android:layout_toRightOf="@id/reset" android:text="@string/add" /> </RelativeLayout>
  37. 37. @chiuki@chiuki Device Preview
  38. 38. @chiuki@chiuki Bigger text on tablets
  39. 39. Resource Folders
  40. 40. @chiuki@chiuki textSize <TextView android:id="@+id/count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="128sp" /> res/layout/activity_main.xml
  41. 41. @chiuki@chiuki res/values/dimens.xml <TextView android:id="@+id/count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="@dimen/counter_size" /> res/layout/activity_main.xml <dimen name="counter_size" value="128sp" /> res/values/dimens.xml
  42. 42. @chiuki@chiuki res/values-sw600dp/dimens.xml <TextView android:id="@+id/count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="@dimen/counter_size" /> res/layout/activity_main.xml <dimen name="counter_size" value="128sp" /> <dimen name="counter_size" value="256sp" /> res/values/dimens.xml res/values-sw600dp/dimens.xml
  43. 43. @chiuki@chiuki Resource Folders Type Variation layout values drawable menu Language & Region: en, fr, fr-rCA, ja Screen size: small, large, sw600dp, h400dp Screen orientation: port, land Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi Platform version: v4, v11, v14 UI mode: car, desk, television, appliance http://developer.android.com/guide/topics/resources/providing-resources.html
  44. 44. @chiuki@chiuki Resource Folders Type Variation layout values drawable menu Language & Region: en, fr, fr-rCA, ja Screen size: small, large, sw600dp, h400dp Screen orientation: port, land Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi Platform version: v4, v11, v14 UI mode: car, desk, television, appliance http://developer.android.com/guide/topics/resources/providing-resources.html res/values-sw600dp/dimens.xml
  45. 45. @chiuki@chiuki Resource Folders Type Variation layout values drawable menu Language & Region: en, fr, fr-rCA, ja Screen size: small, large, sw600dp, h400dp Screen orientation: port, land Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi Platform version: v4, v11, v14 UI mode: car, desk, television, appliance http://developer.android.com/guide/topics/resources/providing-resources.html res/drawable-hdpi/ic_launcher.png
  46. 46. @chiuki@chiuki Resource Folders Type Variation layout values drawable menu Language & Region: en, fr, fr-rCA, ja Screen size: small, large, sw600dp, h400dp Screen orientation: port, land Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi Platform version: v4, v11, v14 UI mode: car, desk, television, appliance http://developer.android.com/guide/topics/resources/providing-resources.html res/drawable-hdpi/ic_launcher.png @2x
  47. 47. @chiuki@chiuki Resource Folders Type Variation layout values drawable menu Language & Region: en, fr, fr-rCA, ja Screen size: small, large, sw600dp, h400dp Screen orientation: port, land Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi Platform version: v4, v11, v14 UI mode: car, desk, television, appliance http://developer.android.com/guide/topics/resources/providing-resources.html res/layout-ja/name.xml
  48. 48. Activity Lifecycle
  49. 49. @chiuki@chiuki onCreate() Activity Lifecycle
  50. 50. @chiuki@chiuki onCreate() Activity Lifecycle
  51. 51. @chiuki@chiuki onCreate() viewDidLoad: Activity Lifecycle
  52. 52. @chiuki@chiuki onCreate() viewDidLoad: onStart() Activity Lifecycle
  53. 53. @chiuki@chiuki onCreate() viewDidLoad: onStart() onResume() Activity Lifecycle
  54. 54. @chiuki@chiuki onCreate() viewDidLoad: onStart() onResume() viewWillAppear: viewDidAppear: Activity Lifecycle
  55. 55. @chiuki@chiuki onCreate() viewDidLoad: onStart() onResume() viewWillAppear: viewDidAppear: onPause() Activity Lifecycle
  56. 56. @chiuki@chiuki onCreate() viewDidLoad: onStart() onResume() viewWillAppear: viewDidAppear: onPause() onStop() Activity Lifecycle
  57. 57. @chiuki@chiuki onCreate() viewDidLoad: onStart() onResume() viewWillAppear: viewDidAppear: onPause() onStop() viewWillDisappear: viewDidDisappear: Activity Lifecycle
  58. 58. @chiuki@chiuki onCreate() viewDidLoad: onStart() onResume() viewWillAppear: viewDidAppear: onPause() onStop() viewWillDisappear: viewDidDisappear: onDestroy() Activity Lifecycle
  59. 59. @chiuki@chiuki onCreate() viewDidLoad: onStart() onResume() viewWillAppear: viewDidAppear: onPause() onStop() viewWillDisappear: viewDidDisappear: onDestroy() viewDidUnload: Activity Lifecycle
  60. 60. @chiuki@chiuki onCreate() viewDidLoad: onStart() onResume() viewWillAppear: viewDidAppear: onPause() onStop() viewWillDisappear: viewDidDisappear: onDestroy() viewDidUnload: Activity Lifecycle
  61. 61. @chiuki@chiuki Visibility
  62. 62. More Activities
  63. 63. @chiuki@chiuki startActivity (explicit) Intent intent = new Intent(this, NumberActivity.class); intent.putExtra("count", count); startActivity(intent);
  64. 64. @chiuki@chiuki startActivity (explicit) Intent intent = new Intent(this, NumberActivity.class); intent.putExtra("count", count); startActivity(intent);
  65. 65. @chiuki@chiuki startActivity (explicit) Intent intent = new Intent(this, NumberActivity.class); intent.putExtra("count", count); startActivity(intent);
  66. 66. @chiuki@chiuki startActivity (implicit) Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://twitter.com/chiuki")); startActivity(intent);
  67. 67. @chiuki@chiuki startActivity (implicit) Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://twitter.com/chiuki")); startActivity(intent);
  68. 68. @chiuki@chiuki startActivity (implicit) Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://twitter.com/chiuki")); startActivity(intent);
  69. 69. @chiuki@chiuki startActivity (implicit) Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://twitter.com/chiuki")); startActivity(intent);
  70. 70. @chiuki@chiuki Register your Activity <activity android:name=".YourActivity"> <intent-filter>    <action android:name="android.intent.action.VIEW" />     <category android:name="android.intent.category.DEFAULT" />     <category android:name="android.intent.category.BROWSABLE" />   <data android:scheme="http" android:host="twitter.com" />   </intent-filter> </activity> AndroidManifest.xml Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://twitter.com/chiuki")); startActivity(intent); Info.plist
  71. 71. @chiuki@chiuki IntentFilter: Action <activity android:name=".YourActivity"> <intent-filter>    <action android:name="android.intent.action.VIEW" />     <category android:name="android.intent.category.DEFAULT" />     <category android:name="android.intent.category.BROWSABLE" />   <data android:scheme="http" android:host="twitter.com" />   </intent-filter> </activity> AndroidManifest.xml Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://twitter.com/chiuki")); startActivity(intent);
  72. 72. @chiuki@chiuki IntentFilter: Data <activity android:name=".YourActivity"> <intent-filter>    <action android:name="android.intent.action.VIEW" />     <category android:name="android.intent.category.DEFAULT" />     <category android:name="android.intent.category.BROWSABLE" />   <data android:scheme="http" android:host="twitter.com" />   </intent-filter> </activity> AndroidManifest.xml Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://twitter.com/chiuki")); startActivity(intent);
  73. 73. @chiuki@chiuki IntentFilter: Category <activity android:name=".YourActivity"> <intent-filter>    <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" />     <category android:name="android.intent.category.BROWSABLE" />   <data android:scheme="http" android:host="twitter.com" />   </intent-filter> </activity> AndroidManifest.xml Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://twitter.com/chiuki")); startActivity(intent);
  74. 74. @chiuki@chiuki IntentFilter: Category <activity android:name=".YourActivity"> <intent-filter>    <action android:name="android.intent.action.VIEW" />     <category android:name="android.intent.category.DEFAULT" />     <category android:name="android.intent.category.BROWSABLE" />   <data android:scheme="http" android:host="twitter.com" />   </intent-filter> </activity> AndroidManifest.xml Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://twitter.com/chiuki")); startActivity(intent);
  75. 75. @chiuki@chiuki Intent Data <activity android:name=".YourActivity"> <intent-filter>    <action android:name="android.intent.action.VIEW" />     <category android:name="android.intent.category.DEFAULT" />     <category android:name="android.intent.category.BROWSABLE" />   <data android:scheme="http" android:host="twitter.com" />   </intent-filter> </activity> Uri uri = getIntent().getData(); AndroidManifest.xml YourActivity.java
  76. 76. @chiuki@chiuki startActivityForResult private static final int REQUEST_CODE_CAMERA = 1; Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, REQUEST_CODE_CAMREA); protected void onActivityResult( int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_CAMERA && resultCode == RESULT_OK) { Bitmap bitmap = (Bitmap) data.getExtras().get("data"); } }
  77. 77. @chiuki@chiuki startActivityForResult private static final int REQUEST_CODE_CAMERA = 1; Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, REQUEST_CODE_CAMERA); protected void onActivityResult( int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_CAMERA && resultCode == RESULT_OK) { Bitmap bitmap = (Bitmap) data.getExtras().get("data"); } }
  78. 78. @chiuki@chiuki Providing Result Intent data = new Intent(); data.putExtra("data", bitmap); setResult(RESULT_OK, data); finish(); protected void onActivityResult( int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_CAMERA && resultCode == RESULT_OK) { Bitmap bitmap = (Bitmap) data.getExtras().get("data"); } }
  79. 79. @chiuki@chiuki Intent Data Intent data = new Intent(); data.putExtra("data", bitmap); setResult(RESULT_OK, data); finish(); protected void onActivityResult( int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_CAMERA && resultCode == RESULT_OK) { Bitmap bitmap = (Bitmap) data.getExtras().get("data"); } }
  80. 80. @chiuki@chiuki Result Code Intent data = new Intent(); data.putExtra("data", bitmap); setResult(RESULT_OK, data); finish(); protected void onActivityResult( int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_CAMERA && resultCode == RESULT_OK) { Bitmap bitmap = (Bitmap) data.getExtras().get("data"); } }
  81. 81. @chiuki@chiuki Share intent Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, message); intent.setType("image/*"); Uri uri = Uri.fromFile(new File(path)); intent.putExtra(Intent.EXTRA_STREAM, uri);
  82. 82. @chiuki@chiuki IntentFilter: Type <activity android:name=".YourActivity"> <intent-filter>    <action android:name="android.intent.action.ACTION_SEND" />     <category android:name="android.intent.category.DEFAULT" />   <data android:mimeType="image/*" />   </intent-filter> </activity> AndroidManifest.xml Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("image/*");
  83. 83. @chiuki@chiuki Intent Data String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); String message = intent.getStringExtra(Intent.EXTRA_TEXT); Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); YourActivity.java Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, message); intent.setType("image/*"); Uri uri = Uri.fromFile(new File(path)); intent.putExtra(Intent.EXTRA_STREAM, uri);
  84. 84. Beyond Activities
  85. 85. @chiuki@chiuki Service BroadcastReceiver ContentProvider Notification
  86. 86. @chiuki@chiuki Service Look ma, no UI!
  87. 87. @chiuki@chiuki Service Long-running
  88. 88. @chiuki@chiuki BroadcastReceiver Respond
  89. 89. @chiuki@chiuki BroadcastReceiver Respond Battery low Wifi connected Incoming SMS App installed Screen off
  90. 90. @chiuki@chiuki ContentProvider Provide data to other apps
  91. 91. @chiuki@chiuki ContentProvider Provide data to other apps Contacts Images Music Calendar
  92. 92. @chiuki@chiuki ContentProvider Internal data (unless you need SQLite interface)
  93. 93. @chiuki@chiuki Notification Notify
  94. 94. @chiuki@chiuki Notify
  95. 95. @chiuki@chiuki Notification Communicate with background Service
  96. 96. @chiuki@chiuki Background Service
  97. 97. Case study
  98. 98. @chiuki Email Outbox
  99. 99. @chiuki
  100. 100. @chiuki@chiuki Notification
  101. 101. @chiuki@chiuki AlarmService
  102. 102. @chiuki@chiuki Connectivity change
  103. 103. Summary
  104. 104. @chiuki@chiuki Summary Hello World Layouts Resource Folders Activity Lifecycle Intents & Components Case Study
  105. 105. @chiuki@chiuki Thank you! http://eepurl.com/lR5uD http://blog.sqisland.com http://twitter.com/chiuki
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×