-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAndroid Notes.rtf
More file actions
2137 lines (2092 loc) · 114 KB
/
Android Notes.rtf
File metadata and controls
2137 lines (2092 loc) · 114 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{\rtf1\ansi\ansicpg1252\cocoartf1265
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww10800\viewh12440\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
\f0\b\fs24 \cf0 \ul \ulc0 Notes on Android from tutorials point
\b0 \ulnone \
\
\
When creating a new Android Application, the Application name is the name of the app, the project\
name will be the same thing, the package name must be unique from all other apps when the\
app enters the google marketplace, and it must have two identifiers separated by spaces.\
Standard practice is if you have a website to do the url backwards then the app name.\
i.e. com.toddsblog.helloworld\
edu.kronenbergt.myfirstapp\
\
\
The AndroidManifest.xml file describes each application component and how they interact. There are\
four main components that can be used:\
Activities - they dictate the UI and handle user interaction to the screen\
Services - they handle background processing associated with an application\
Broadcast Receivers - they handle communication between Android OS and applications\
Content Providers - they handle data and database management issues\
\
Activities:\
Represents a single screen with a user interface. One of these activities needs to be marked\
as the one that is started when the application is launched. An activity is implemented as a\
subclass of the Activity class:\
public class MainActivity extends Activity \{ \}\
\
Services:\
A service does background stuff, performing long-running operations. Like it might play music,\
or it might fetch data over the network without blocking user interaction with an activity. A\
service is implemented as a subclass of the Service class:\
public class MyService extends Service \{ \}\
\
Broadcast Receivers:\
They just respond to broadcast messages from other applications or from the system. Can\
also let other applications know that some data has been downloaded that is available for them\
to use. A broadcast receiver is implemented as a subclass of the BroadcastReceiver class and\
each message is broadcasted as an Intent object:\
public class MyReceiver extends BroadcastReceiver \{ \}\
\
Content Providers:\
Supplies data from one application to others on request. These requests are handles by the\
methods of the ContentResolver class. The data may be stored in the file system, the\
database, or somewhere else. A content provider is implemented as a subclass of the\
ContentProvider class and must implement a standard set of APIs that enable other\
applications to perform transactions:\
public class MyContentProvider extends ContentProvider \{ \}\
\
Additional Components:\
Fragments - represents a behavior or a portion of user interface in an Activity\
Views - UI elements that are drawn onscreen including buttons, lists, forms, etc\
Layouts - View hierarchies that control screen format and appearance of the views\
Intents - Message wiring components together\
Resources - External elements, such as strings, constants, and drawable pictures\
Manifest - Configuration file for the application\
\
\
Folders in the Android package:\
src - contains the .java source files, by default includes a MainActivity.java file having an\
activity class that runs when the app is launched.\
gen - contains the .R file, a computer generated file that references all the resources found\
in the project. Don\'92t modify this.\
bin - contains the Android package files .apk built by the ADT during the build process and\
everything else needed to run an Android app.\
res/drawable - holds the drawable objects that are designed for different density screens.\
res/layout - hold files that define the app\'92s user interface. Can refer to these files in code as\
follows: R.layout.activity_main <- refers to the activity_main.xml file\
res/values - hold other various XML files that contain a collection of resources, such as strings\
and color definitions.\
AndroidManifest.xml - the manifest file which describes the fundamental characteristics of the\
app and defines each of its components.\
\
\
Main Activity File:\
The MainActivity.java file is the application file that gets opened when the app is launched.\
\
Main methods:\
public void onCreate(Bundle savedInstanceState) \{\
super.onCreate(savedInstanceState);\
setContentView(R.layout.activity_main);\
\}\
public boolean onCreateOptionsMenu(Menu menu) \{\
getMenuInflater().inflate(R.menu.activity_main, menu);\
return true;\
\}\
\
The Manifest File:\
All components of the application must be declared in the AndroidManifest.xml file. This file\
works as an interface between the Android OS and the application.\
\
In the <application> tag of the manifest are included all the components related to the\
application. Like the launcher icon - android:icon=\'93@drawable/ic_launcher\'94, the app name\
listed on the launcher icon - android:label=\'93@string/app_name\'94, and the theme of the app - \
android:theme=\'93@style/AppTheme\'94.\
\
In the application tag is the <activity> tag which is used to specify an activity through its name\
attribute that specifies the fully qualified class name of the Activity subclass by using the\
android.name attribute and setting it equal to the package name followed by the main activity -\
android:name=\'93edu.kronenbergt.firstapp.MainActivity\'94. Also it holds the string used as the label\
for the activity - android:label=\'93@string/app_name\'94.\
\
Inside the activity tag is the <intent_filter> tag which holds the action for the intent filter to\
indicate that this activity serves as the entry point for the application, so this is where you\
specify what activity starts when the app is launched -\
<action android:name=\'93android.intent.action.MAIN\'94 />\
Also the category for the intent filter is named to indicate that the application can be launched\
from the device\'92s launcher icon -\
<category android:name=\'93android.intent.category.LAUNCHER\'94 />\
\
The @string refers to the strings.xml file.\
\
List of rage used in the manifest file to specify different Android application components:\
<activity>, <service>, <receiver>, <provider>\
\
The Strings File:\
The strings.xml file is located in the res/values folder and it contains all the text that the app\
uses. So anytime a string of text is to be used, it should be defined in the strings.xml file and\
called from there using the @string/ call form. To define a string in the strings.xml file:\
<string name=\'93hello_world\'94>Hello fine world out there!</string>\
\
The Dimens File:\
Under res/values is the dimens.xml file in which you can specify different screen or text block\
margins. Can use these in the activity_main.xml file under the <TextView> tag by using -\
android:padding=\'93@dimen/blah\'94\
\
The R File:\
The gen/com.example.helloworld/R.java file is the glue between the activity java files and the\
resource files. It is generated automatically and should never be modified.\
\
The Layout File:\
The activity_main.xml is a layout file available in the res/layout directory. It is referenced by the\
application when building its interface. This file will be modified frequently to change the layout\
of the app. It can have either a Relative Layout or Linear Layout using their respective tags,\
and the <Textview> tag is an Android control used to build the GUI and it has various attributes\
to set the layout attributes of the text?\
In the <Textview> tag, when using a <RelativeLayout>, to make something appear in the\
middle of the screen use:\
android:layout_centerHorizontal=\'93true\'94\
android:layout_centerVertical=\'93true\'94\
and to change the size of the text (to let\'92s say 30 pixels) use:\
android:textSize=\'9330sp\'94\
\
\
Resources:\
All the resources used in the app are held in the res/ directory of the project. Different kinds of\
resources should be organized into their own specific folders in under the res/ directory.\
Use these folder names for various kinds of resources:\
anim/ - xml files that define property animations. Accessed via the R.anim class.\
color/ - xml files that define a state list of colors. Accessed via the R.color class.\
drawable/ - image files accessed from the R.drawable class.\
layout/ - xml files that define a user interface layout. Accessed via R.layout class.\
menu/ - xml files that define application menus, accessed via the R.menu class.\
raw/ - arbitrary files to save in their raw form. To get them call the\
Resources.openRawResource() method with the resource ID, which is\
R.raw.filename to open the raw file.\
values/ - xml files that contain simple values, like strings, integers, colors. Here are\
some file name conventions for using in this folder:\
arrays.xml - accessed via R.array class\
integers.xml - accessed via R.integer class\
bools.xml - accessed via R.bool class\
colors.xml - accessed via R.color class\
dimens.xml - accessed via R.dimen class\
strings.xml - accessed via R.string class\
styles.xml - accessed via R.style class\
xml/ - arbitrary xml files can be read at runtime by calling Resources.getXML().\
Can save various config files here which will be used at runtime.\
\
\
Alternative Resources:\
Should use alternative resources to support specific device configurations, like different\
drawable resources for different screen resolutions, and alternative string resources for\
different languages. At runtime, Android detects the current device configs and loads the\
appropriate resources from the application.\
To make config-specific resource alternatives create a new directory in the res/ directory in the\
form: resoure_name-config_qualifier. The qualifier will specify an individual config for which \
those resources are to be used. Check official documentation for a complete lis of qualifiers\
for different types of resources.\
i.e. layout-ar/ <- this specifies a layout for arabic language\
main.xml\
\
Accessing Resources:\
Accessing resources in code:\
When the Android app is compiled, an R class gets generated, which contains resource\
IDs for all the resources in the res/ directory. You use the R class to access that\
resource using sub-directory and resource name or directly resource ID.\
i.e. To access res/drawable/myimage.png and set an ImageView:\
ImageView imageView = (ImageView) findViewById(R.id.myimageview);\
imageView.setImageResource(R.drawable.myimage);\
i.e.\
TextView msgTextView = (TextView) findViewById(R.id.msg);\
msgTextView.setText(R.string.helloworld);\
i.e. in the onCreate() method:\
super.onCreate(savedInstanceState);\
setContentView(R.layout.activity_main); <\'97 sets content to activity_main.xml\
\
Accessing resources in XML:\
To access resources in an xml file, say to access a color, do this:\
android:textColor=\'93@color/colorName\'94\
To access a string:\
android:text=\'93@string/stringName\'94\
\
\
Android Activities:\
The Main Activity initiates a program with the onCreate() method. Below is an Activity Lifecycle\
Diagram:\
\
onCreate \'97> [CREATED] \'97> onStart() \'97> [STARTED] \'97> onResume() \'97> [RESUMED (visible)]\
^ ^ /\
onRestart() , onStart() onResume() onPause()\
^ ^ /\
onDestroy() <\'97 [STOPPED (hidden)] <\'97 onStop() <\'97 [PAUSED (partially visible)]\
/\
[DESTROYED]\
\
Each of these is called a Callback, they are listed below:\
onCreate() - the first callback and called when the activity is first created\
onStart() - called when the activity becomes visible to the user\
onResume() - called when the user starts interacting with the application\
onPause() - the paused activity does not receive user input and cannot execute\
code, called when the current activity is being paused and the\
previous activity is being resumed\
onStop() - called when the activity is no longer visible\
onDestroy() - called before the activity is destroyed by the system\
onRestart() - called when the activity restarts after stopping it\
\
\
Android Services:\
A service is a component that runs in the background to perform long-running operations\
without needing to interact with the user. A service can take two states:\
Started - a service is started when an application component, such as an\
activity, starts it by calling startService(). Once started, it can run in\
the background indefinitely, even if the component that started it\
is destroyed.\
Bound - a service is bound when an application component binds to it by\
calling bindService(). A bound service offers a client-server\
interface that allows components to interact with the service, send\
requests, get results, and even do so across processes with\
interprocess communication (IPC).\
\
Service Lifecycle Diagram:\
Call to startService():\
startService() \'97> onCreate() \'97> onStartCommand() \'97> [SERVICE RUNNING]\
\'97> onDestroy()\
\
Call to bindService():\
bindService() \'97> onCreate() \'97> onBind() \'97> onUnbind() \'97> onDestroy()\
\
To create a Service you create Java class that extend the Service base class or one of its\
existing subclasses. The service base class defines the callback methods.\
\
Service callback methods:\
onStartCommand() - the system calls this method when another component, such as\
an activity, requests that the service be started, by calling\
startService(). If you implement this method, it is your\
responsibility to stop the service when its work is done, by calling\
stopSelf() or stopService().\
onBind() - the system calls this method when another component wants to bind with\
the service by calling bindService(). If you implement this method, you\
must provide an interface that clients use to communicate with the service,\
by returning an IBinder object. You ust always implement this method, but\
if you don\'92t want to allow binding, then you should return null.\
onUnbind() - the system calls this method when all clients have disconnected from a\
particular interface published by the service.\
onRebind() - the system calls this method when new clients have connected to the\
service, after it had previously been notified that all had disconnected in\
its onUnbind(Intent).\
onCreate() - the system calls this method when the service is first created using\
onStartCommand() or onBind(). This call is required to perform one-time\
setup.\
onDestroy() - the system calls this method when the service is no longer used and is\
being destroyed. Your service should implement this to clean up any\
resources such as thread, registered listeners, receivers, etc.\
\
\
Android Broadcast Receivers:\
Broadcast receivers respond to broadcast messages from other applications of from the\
system itself. These messages are sometimes called events or intents. There are two\
important steps to make BroadcastReceiver work for the system broadcasted intents:\
Creating the Broadcast Receiver\
Registering the Broadcast Receiver\
\
Creating the Broadcast Receiver:\
It\'92s implemented as a subclass of BroadcastReceiver class and overriding the\
onReceive() method where each message is received as an Intent object parameter.\
i.e.\
public class MyReceiver extends BroadcastReceiver \{\
@Override\
public void onReceive(Context context, Intent intent) \{\
Toast.makeText(context, \'93Intent Detected.\'94, Toast.LENGTH_LONG.show();\
\} \}\
\
Registering a Broadcast Receiver:\
Registered in the AndroidManifest.xml file, like so in the <application tag:\
<receiver android:name=\'93MyReceiver\'94>\
<intent-filter>\
<action android:name=\'93android.intent.THE_INTENT_NAME\'94>\
</action>\
</intent-filter>\
</receiver>\
\
There are several system generated events defined as final static fields in the Intent class,\
here are a few of the important ones:\
android.intent.action.BATTERY_CHANGED - sticky broadcast containing charging\
state, level, and other battery info.\
android.intent.action.BATTERY_LOW - indicates low battery\
android.intent.action.BATTER_OKAY - indicates battery is now okay after being low\
android.intent.action.BOOT_COMPLETED - this is broadcast once, after the system\
has finished booting.\
android.intent.action.BUG_REPORT - shows activity for reporting a bug.\
android.intent.action.CALL - performs a call to someone specified by the data.\
android.intent.action.CALL_BUTTON - the user pressed the \'93call\'94 button to go to the\
dialer or other appropriate UI for placing a call.\
android.intent.action.DATE_CHANGED - the date has changed\
android.intent.action.REBOOT - have the device reboot.\
\
Can have the application send custom intents by using the sendBroadcast() method inside the\
activity class. If you use the sendStickyBroadcast(Intent) method then the intent is sticky,\
meaning the Intent being sent stays around after the broadcast is complete.\
i.e.\
public void broadcastIntent(View view) \{\
Intent intent = new Intent();\
intent.setAction(\'93com.example.CUSTOM_INTENT\'94);\
sendBroadcast(intent);\
\}\
\
The intent must also be registered in a similar way as the register system generated intent in\
the <application tag of the AndroidManifest.xml file. The only different is you change the line:\
<action android:name=\'93com.example.CUSTOM_INTENT\'94>\
\
\
Android Content Providers:\
A content provider component supplies data from one application to others on request. The\
requests are handled by the method of the ContentResolver class. A content provider can\
store data in a database, in files, or over a network. Content providers are only used to share\
data across applications. They let you centralize content in one place and have many different\
application access it as needed. It behaves much like a database, you can query it, edit its\
content, add or delete using insert(), update(), delete(), and query(). In most cases the data\
is stored in an SQLite database. A content provider is implemented as a subclass of\
ContentProvider and must implement a standard set of APIs that enable other applications to\
perform transactions.\
public class MyContentProvider extends ContentProvider \{ \}\
\
To query a content provider you specify the query string in the form of a URI which has the\
following format:\
<prefix>://<authority>/<data_type>/<id>\
\
Parts of the URI:\
prefix - this is always set to content://\
authority - this specifies the name of the content provider, for example, contacts,\
browser, etc. For third-party content providers, this could be the fully\
qualified name, such as com.example.statusprovider.\
data_type - this indicates the type of data that this particular provider provides. For\
example, if you are getting all the contacts from the Contacts content\
provider, then the data path would be people and the URI would like like:\
content://contacts/people\
id - this specifies the specific record requested. For example, if you are\
looking for contact number 5 in the Contacts content provider then the\
URI would look like this: content://contact/people/5\
\
To create a content provider a number of simple steps are involved:\
- Create a Content Provider class that extends ContentProvider base class.\
- Define the content provider URI address which will be used to access the content.\
- Create a database to keep the content. Usually Android uses SQLite and the\
framework needs to override onCreate() method which will use SQLite Open Helper\
method to create or open the provider\'92s database. When the application is launched\
the onCreate() handler of each of its Content Providers is called on the main\
application thread.\
- Implement Content Provider queries to perform different database specific operations.\
- Register the Content Provider in the AndroidManifest.xml file using the <provider> tag.\
\
List of methods you need to override in Content Provider class:\
onCreate() - called then the provider is started\
query() - receives a request from a client, result is returned as a Cursor\
object\
insert() - inserts a new record into the content provider\
delete() - deletes an existing record from the content provider\
update() - updates an existing record from the content provider\
getType() - returns the MIME type of the data at the given URI\
\
\
Android Fragments:\
A Fragment is a piece of an application\'92s user interface or behavior that can be placed in an\
Activity which enables more modular activity design. A fragment is a kind of sub-activity.\
A fragment has its own layout and ties own behavior with its own lifecycle callbacks.\
You can add or remove fragments in an activity while the activity is running.\
You can combine multiple fragments in a single activity to build a multi-pane UI.\
Fragment life cycle is closely related to lifecycle of its host activity so when the activity is\
paused, all fragments available in the activity will also be stopped.\
A fragment can implement behavior that has no user interface component.\
Create a Fragment by extending the Fragment class, insert a fragment into an activity layout\
by declaring the fragment in the activity\'92s layout file, using the <fragment> tag.\
\
Fragment Life Cycle:\
Phase 1: When a fragment gets created:\
onAttach() \'97> onCreate() \'97> onCreateView() \'97> onActivityCreated()\
Phase 2: When the fragment becomes visible:\
onStart() \'97> onResume()\
Phase 3: When the fragment goes into the background mode:\
onPaused() \'97> onStop()\
Phase 4: When the fragment is destroyed:\
onPaused() \'97> onStop() \'97> onDestroyView() \'97> onDestroy() \'97> onDetach()\
\
Using Fragments:\
Decide how many fragments to use in an activity. For example, two fragments can be\
used to handle landscape and portrait views of the device.\
Create the appropriate number of classes to extend the fragment class. Override any\
of the fragment callback functions based on your requirements.\
Corresponding to each fragment you will need to create layout XML files.\
Finally, modify the activity file to define the actual logic of replacing fragments based on\
your requirements.\
\
List of important methods to override in a fragment class:\
onCreate() - system calls this when creating the fragment. You should initialize essential\
components of the fragment that you want to retain when the fragment is\
paused or stopped, then resumed.\
onCreateView() - system calls this when it\'92s time for the fragment to draw its UI for the\
first time. To draw a UI for the fragment, you must return a View\
component from this method that is the root of the fragment\'92s\
layout. You can return null if the fragment does not provide a UI.\
onPause() - system calls this method as the first indication that the user is leaving the\
fragment. This is usually where you should commit any changes that\
should be persisted beyond the current user session.\
\
\
Android Intents and Filters:\
Intents are basically used to call another activity. \
An Android intent is an object carrying an intent, i.e. like a message from one component to\
another component within the application or outside the application. Intents can communicate\
messages among any of the three core components of an application - activities, services, and\
broadcast receivers. An intent object is a passive data structure holding an abstract description\
of an operation to be performed.\
\
i.e. For an activity to launch an email client and send an email using the Android device, the\
activity would send an ACTION_SEND along with the appropriate chooser, to the\
Android Intent Resolver. The specified chooser gives the proper interface for the user\
to pick how to send the email data.\
i.e. For an activity that needs to open URL in a web browser on the Android device, the activity\
will send ACTION_WEB_SEARCH intent to the Android Intent Resolver to open the\
given URL in the browser. The Intent Resolver parses through a list of activities and\
chooses the one that would best match your Intent, in this case, the web browser\
activity. The Intent Resolver then passes the web page to the web browser and start the\
web browser activity.\
\
There are separate mechanisms for delivering intents to each type of component:\
Context.startActivity() - intent object passed to this method to launch a new activity or\
get an existing activity to do something\
Context.startService() - intent object is passed to this method to initiate a service or\
deliver new instructions to an ongoing service\
Context.sendBroadcast() - intent object is passed to this method to deliver the message\
to all interested broadcast receivers\
\
Intent Objects:\
An intent object is a bundle of info which is used by the component that receives the\
intent plus info used by the Android system. An intent object can contain the following\
components based on what it is communicating or going to perform:\
Action, Data, Category, Extras, Flags, Component Name\
\
Action:\
This is a mandatory part of the intent object and is a string naming the action to\
be performed, or in the case of broadcast intents - the action that took place and\
is being reported. The action largely determines how the rest of the intent object\
is structured. The intent class defines a number of action constants\
corresponding to different intents. An action in an intent object can be set by the\
setAction() method and read by the getAction() method.\
\
Data:\
The URI of the data to be acted on and the MIME type of that data. For example,\
if the action field is ACTION_EDIT, the data field would contain the URI of the\
document to be displayed for editing.\
The setData() method specifies data only as a URI, setType() specifies it only as\
a MIME type, and setDataAndType() specifies it as both a URI and a MIME type.\
The URI is read by getData() and the type by getType().\
\
Category:\
An optional part of the intent object, it\'92s a string containing additional info about\
the kind of component that should handle the intent. The addCategory() method\
places a category in an intent object, removeCategory() delete a category\
previously added, and getCategories() gets the set of all categories currently in\
the object.\
\
Extras:\
This will be in key-value pairs for additional info that should be delivered to the\
component handling the intent. The extras can be set and read using the\
putExtras() and getExtras() methods.\
\
Flags:\
These flags are option part of intent object and instruct the Android system how\
to launch an activity, and how to treat it after it\'92s launched.\
\
Component Name:\
Optional field, the ComponentName object, representing either Activity, Service,\
or BroadcastReceiver class. If it is set, the intent object is delivered to an\
instance of the designated class otherwise Android uses other info in the intent\
object to locate a suitable target. The component name is set by\
setComponent(), setClass(), or setClassName() and read by getComponent().\
\
Types of Intents:\
Explicit Intents:\
These designate the target component by its name and they are typically used\
for application-internal messages, such as an activity starting a subordinate\
service or launching a sister activity.\
Implicit Intents:\
These do not name a target and the field for the component name is left blank.\
Implicit intents are often used to activate components in other applications. The\
target component which receives the intent can use the getExtras() method to\
get extra data sent by the source component.\
\
Intent Filters:\
Intent filters are used to pinpoint the set of Activites, Services, and Broadcast Receivers\
that can handle the intent with the help of specified set of action, categories, and data\
schemes associated with the intent. You use the <intent-filter> tag in the manifest file\
to list down actions, categories, and data types associated with any activity, service, or\
broadcast receiver.\
Once the activity is defined with filters, other activities will be able to invoke this activity\
using with either the android.intent.action.VIEW, or using\
com.example.intentedemo.LAUNCH action provided their category is\
android.intent.category.DEFAULT.\
The <data> element specifies the data type expected by the activity to be called.\
A filter must contain at least one action element. A filter may list zero, one, or more\
categories. If more than one category is mentioned then every category in the intent\
object must match a category in the filter. Each <data> element can specify a URI and a\
data type (MIME media type). There are separate attributes like scheme, host, port, and\
path for each part of the URI. For an intent object that contains both a URI and a data\
type, the data type must match a type lister in the filter.\
\
i.e.\
<activity android:name=\'93blah\'94\
android:label=\'93@string/blah\'94>\
<intent-filter>\
<action android:name=\'93android.intent.action.VIEW\'94 />\
<action android:name=\'93com.example.intentdemo.LAUNCH\'94 />\
<category android:name=\'93android.intent.category.DEFULAT\'94 />\
<data android:scheme=\'93http\'94 />\
</intent-filter>\
</activity>\
\
\
Android UI Layouts:\
The basic building block for UI is a View object, which is created from the View class and\
occupies a rectangular area on the screen and is responsible fro drawing and event handling.\
View is the base class for widgets, which are used to create interactive UI components like\
buttons, text fields etc.\
The ViewGroup is a subclass of View and provides invisible containers that holds other Views\
or other ViewGroups and defines they layout properties.\
On the third level there are different layouts which are subclasses of the ViewGroup class. A\
typical layout defines the visual structure for Android UI and can be created either at runtime\
using View/ViewGroup objects or you can declare your layout using simple XML file\
main_layout.xml which is located in the res/layout folder of the project.\
A layout maybe contain any type of widgets like buttons, text boxes, etc.\
Once the layout is defined, you can load the layout resource from the application code, in the\
Activity.onCreate() method like so:\
public void onCreate(Bundle savedInstanceState) \{\
super.onCreate(savedInstanceSate);\
setContentView(R.layout.activity_main); \}\
\
Layout Types:\
Different layout types provide different view, look and feel:\
\
Linear Layout - a view group that aligns all children in a single direction - vertically or\
horizontally.\
Relative Layout - a view group that displays child views in relative positions.\
Table Layout - groups views into rows and columns.\
Absolute Layout - enables you to specify the exact location of its children.\
Frame Layout - a placeholder on screen that you can use to display a single view.\
List View - a view group the displays a list of scrollable items.\
Grid View - a view group that displays items in a two-dimensional, scrollable grid.\
\
Layout Attributes:\
These are the things in the XML file that follow the \'93android:\'94, like id, layout_width, etc.\
The define the properties of the layout.\
\
dp: density-indepent pixels\
sp: scale-independent pixels\
pt: points, which is 1/72 of an inch\
px: pixels\
mm: millimeters\
in: inches\
\
Width and heigh are usually specified with the constants: wrap_content or fill_parent.\
wrap_content tells the view to size itself to the dimensions required by its content.\
fill_parent tells the view to become as big as its parent view.\
The gravity attribute play an important role in positing the view object and it can take\
one or more constants, separated by \'93 | \'94, it takes constants like top, bottom, left, fill,\
center_vertical, clip_horizontal, start, end, etc.\
\
View Identification:\
A view object may have a unique ID assigned to it which will identify it uniquely within\
the tree. Syntax: android:id=\'93@+id/my_button\'94\
\
The @ symbol indicates that the XML parser should parse and expand the rest of the\
ID string and identify it as an ID resource.\
\
The + symbol means that this is a new resource name that must be created and added\
to the resources. To create an instance of the view object and capture it from the layout,\
use this:\
Button myButton = (Button) findViewById(R.id.my_button);\
\
\
Android UI Controls:\
A UI is everything the user can interact with. A View is an object that draws something on the\
screen that the user can interact with, and a ViewGroup is an object that holds other Views and\
ViewGroup objects in order to define the layout of the UI. Basically a View is a widget.\
Examples:\
<TextView>, <Button>, <EditText>, <ImageButton>, <CheckBox>, <ToggleButton>,\
<AutoCompleteTextView>, <RadioButton>, <RadioGroup>, <ProgressBar>, <Spinner>,\
<TimePicker>, <DatePicker>\
\
Create UI Controls:\
Can create a View with a unique ID to identify it from everything else in the tree of\
Views: android:id=\'93@+id/text_id\'94\
\
i.e. To create a Text box to display to the user:\
XML file (put this inside a layout type:\
<TextView android:id\'94@+id/textblah\'94\
android:attributeblah=\'93blah\'94\
android:text=\'93blahblah\'94 />\
In Code:\
TextView myText = (TextView) findViewById(R.id.textblah);\
\
\
Event Handling:\
Events are a way to collect data about the user\'92s interaction with interactive components of the\
app, like button presses or screen touches. The Android framework maintains an event queue\
into which events are placed as they occur and then each event is removed from the queue on\
a FIFO basis. You can capture these events in your program and take appropriate action.\
\
There are three concepts related to the Android Event Management:\
Event Listeners - The Event Listener is the object that receives notification when an\
event happens. The View class is mainly involved in building up a\
GUI. That same View class provides a number of Event Listeners.\
Event Listeners Registration - this is a process by which an Event Handler gets\
registered with an Event Listener so that the handler is\
called when the Event Listener fires the event.\
Event Handlers - When an event happens and we have registered an event listener for\
the event, the event listener calls the Event Handlers, which is the\
method that actually handles/operates on the event.\
\
\ul Event Handlers\ulnone \ul Event Listener and Description\ulnone \
onClick() OnClickListener() - called when the use either clicks or touches or\
focuses upon any widget like a button, text,\
image, etc.\
onLongClick() OnLongClickListener() - called when the user clicks, touches, or\
focuses on any widget for one or more\
seconds.\
onFocusChange() OnFocusChangeListener() - called when the widget looses its focus\
(user goes away from the View item).\
onKey() OnFocusChangeListener() - called when user is focused on the\
item and presses or releases a\
hardware key on the device.\
onTouch() OnTouchListener() - called when the user presses, releases, or\
makes any gesture on the screen.\
onMenuItemClick() OnMenuItemClickListener() - called when the user selects a menu\
item.\
\
There are many more event handlers available as part of the View class.\
\
Event Listeners Registration:\
Event Registration is the process by which an Event Handler gets registered with an\
Event Listener so that the handler is called when the event listener fires the event.\
There are several ways to register an event listener for any event, but here are the top\
three ways:\
Using an Anonymous Inner Class\
Activity class implement the Listener Interface\
Using Layout file activity_main.xml to specify the event handler directly\
\
Styles and Themes:\
Use styles and Themes in the activity_main.xml file to stylize Views in the form;\
android:attribute=\'93value\'94\
You define styles in an XML resource in the res/values/styles file, in the form:\
<style name=\'93StyleName\'94>\
<item name=\'93android:attribute\'94>value</item>\
\'85\
</style>\
Use styles in the activity_main.xml file inside a View tag like so:\
<ViewTag\
\'85\
style=\'93@style/StyleName\'94\
\'85 />\
\
Style Inheritance:\
For inheriting custom style:\
Android supports style inheritance similar to CSS. Use this to inherit properties from an\
existing style and then change only the properties you want different. To do this use the\
following form:\
<style name=\'93ParentName.thisName\'94>\
<item \'85\
</style>\
Can do as many generations as you want using dots:\
i.e. <style name=\'93GGrandParentName.GrandParentName.ParentName.thisName\'94>\
i.e. <style name=\'93CustomFontStyle.LargeFont.Blue.BlackBckgrnd\'94>\
\
For inheriting Android built-in styles you must do things a little differently:\
<style name=\'93thisStyleName\'94 parent=\'93@android:style/ParentName\'94>\
<item \'85\
</style>\
\
Android Themes:\
A theme is just a style applied to an entire Activity or application, rather than to an\
individual View. When a style is applied as a theme, every View in the activity of app will\
apply each style property that it supports.\
To set a theme you edit the AndroidManifest.xml file.\
To set a theme for the entire app you edit the <application> tag:\
<application\
android:theme=\'93@style/blah\'94\
\'85\
To set a theme for one activity in an app you edit the <activity> tag:\
<activity\
android:theme=\'93@style/blah\'94\
\'85\
\
The Android platform provides a large collection of styles and themes, found in the\
R.style class. To use style listed there, replace all underscores in the style name with a\
period, so that applying \'93Theme_NoTitleBar\'94 would be\
\'93@android:style/Theme.NoTitleBar\'94.\
\
\
Android Custom Components:\
Android provides the means for creating custom widgets/Views/components. If you just need\
to make small changes to an existing widget or layout you can simply subclass the widget or\
layout and override its methods.\
\
So the simplest way to make a custom View is to make a subclass of a built-in View. You need\
to write constructors corresponding to all the constructors of the base class. To implement\
custom drawing/sizing of the View then you need to override the\
onMeasure(int widthMeasureSpec, int heightMeasureSpec) and the\
onDraw(Canvas canvas) methods.\
The onMeasure() method coordinates with the layout manager to report the widget\'92s width and\
height, and you need to call setMeasuredDimension(int width, int height) from inside this\
method to report the dimensions.\
You can implement a custom drawing of the View inside the onDraw(Canvas canvas) method,\
where android.graphics.Canvas is pretty similar to its counterpart in Swing, and has methods\
like drawRect(), drawLine(), drawString(), drawBitmap(), etc.\
\
Instantiating a Custom View (2 ways):\
Using code inside Activity class:\
Basically same way as instantiating a built-in View. In the onCreate() method of\
an Activity use this form:\
CustomViewType ObjectName = new CustomViewType(this);\
setContentView(ObjectName);\
\
Using Layout XML File:\
Same way as instantiating a built-in View in the activity_main.xml file except the\
tag you use is the app\'92s package name followed by a period and the name of the\
custom View:\
<com.example.firstapp.CustomViewType\
android:attribute=\'93value\'94\
\'85\
/>\
You can use all the attributes that are used by the Parent built-in View.\
\
Custom Components with Custom Attributes (using attars.xml):\
You can make custom attributes for your custom Views.\
1. You have to define the custom attributes in a new xml file under res/values and\
call it attars.xml:\
<resources>\
<declare-styleable name=\'93CustomViewType\'94>\
<attr name=\'93attributeName\'94 format=\'93datatype\'94 />\
<attr name=\'93fancyText\'94 format=\'93boolean\'94 >\
</declare-styleable>\
</resources>\
2. Need to read these attributes from the layout XML file and set them for the\
component. This logic will go in the constructors that get passed on AttributeSet, which\
is what contains the XML attributes. To read the values in the XML, you need to create\
a TypedArray from the AttributeSet, then use that to read and set the values as shown:\
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CstmViewType);\
final int N = a.getIndexCount();\
for (int i=0; i<N ++i) \{\
int attr = a.getIndex(i);\
switch (attar) \{\
case R.styleable.CstmViewType_attrName:\
String delimiter = a.getString(attr);\
\'85do something with delimiter\'85\
break;\
case R.styleable.CstmViewType_anotherAttrName:\
boolean fancyText = a.getBoolean(attr, false);\
\'85 do something with fancyText\'85\
break;\
\} \}\
a.recycle();\
3. Finally you use your defined attributes in your layout xml file in the custom View in the form:\
custom:attrName=\'93value\'94\
And make sure inside the Layout tag that you add the line:\
xmlns:custom=\'93http://schemas.android.com/apk/res/package name\'94\
i.e.\
xmlns:custom=\'93http://schemas.android.com/apk/res/com.example.firstapp\'94\
\
\
Drag and Drop:\
Moving data from one View to another using drag and drop gesture. The framework includes\
three important elements to support the functionality:\
Drag event class\
Drag listeners\
Helper methods and classes\
\
The Drag/Drop Process:\
Four steps or states in the drag and drop process.\
Started:\
This event occurs when you start dragging an item in a layout, your app calls\
startDrag() method to tell the system there is a drag. The arguments inside the\
startDrag() method provide the data to be dragged, metadata for this data and a\
callback for drawing the drag shadow. The system first responds by calling back\
to the app to get the draw shadow. Next the system sends a drag event with\
action type ACTION_DRAG_STARTED to the registered drag event listeners for\
all the View objects in the current layout. To continue to receive drag events,\
including drop events, a drag event listener must return true. If the drag event\
listener returns false then it will not receive drag events for the current operation\
until the system sends a drag event with the action type\
ACTION_DRAG_ENDED.\
Continuing:\
The user continues to drag. System sends ACTION_DRAG_ENTERED action\
followed by ACTION_DRAG_LOCATION action to the registered event listener\
for the View where dragging point enters. The listener mate choose to alter its\
View object\'92s appearance in response to the event or can react by highlighting its\
View.\
Dropped:\
The user releases the dragged item within the bounding box of a View. The\
system send the View object\'92s listener a drag even twitch action type\
ACTION_DROP.\
Ended:\
Just after the action type ACTION_DROP, the system sense out a drag event\
with action type ACTION_DRAG_ENDED to indicate the drag operation is over.\
\
DragEvent Class:\
The DragEvent represents an event that is sent out by the system at various times\
during a drag and drop operation. This class provides a few constants and methods to\
use during the drag/drop process.\
Constants:\
ACTION_DRAG_STARTED\
ACTION_DRAG_ENTERED\
ACTION_DRAG_LOCATION - if drag shadow is within the View\'92s bounding box\
ACTION_DRAG_EXITED - when user has moved drag shadow out of the View\
ACTION_DROP\
ACTION_DRAG_ENDED\
Methods:\
int getAction() - inspect the action value of this event.\
ClipData getClipData() - returns the ClipData object sent to the system as part of\
the call to startDrag()\
ClipDescription getClipDescription() - returns the ClipDescription object\
contained in the ClipData.\
boolean getResult() - returns an indication of the result of the drag/drop operation\
float getX() - gets the x-coordinate of the drag point\
float getY() - gets the y-coordinate of the drag point\
String toString() - returns a string representation of this DragEvent object.\
\
Listening for Drag Event:\
For a View to respond to a drag event the View needs to implement\
View.OnDragListener or setup onDragEvent(DragEvent) callback method. When the\
system calls the method or listener it passes them to a DragEvent object.\
To start a drag event, you start by creating a ClipData and ClipData.Item for the data\
being moved. As part of the ClipData object, supply metadata that is stored in a\
ClipDescription object within the ClipData. For a drag and drop operation that does not\
represent data movement you probably just wanna use null instead of an actual object.\
Next either extend View.DragShadowBuilder to create a drag shadow for dragging the\
View or just use View.DragShadowBuilder(View).\
\
\
Android Notifications:\
\
Location Based Services:\
\
Android Sending Email:\
\
Android Sending SMS:\
\
Android Phone Calls:\
\
\
\
\b \ul Notes from Google\'92s Android Developer Training:
\b0 \ulnone \
\
When referencing a method by putting it in a View\'92s xml code (i.e. android:onClick=\'93sendMessage\'94)\
that method in the Activity source code, must be public, have a void return value, and have a View as\
the only parameter. i.e. public void sendMessage(View view) \{ \}\
\
An intent is an object that provides runtime binding between separate components (such as two\
activities). The intent represents an app\'92s \'93intent to do something\'94.\
\
Every activity is invoked by an Intent. You can get the Intent that started the activity by calling\
getIntent(), which returns an Intent object, and retrieve the data contained within it using\
intent.getblah().\
\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
\b \cf0 Action Bar:
\b0 \
An Action Bar gives a dedicated space for giving an app an identity and indicating the user\'92s location\
in the app, access to important actions (like search bar), and support for navigation and view\
switching. In its most basic form the action bar displays the title for the activity and the app icon on\
the left. To have an Action Bar the app has to use an activity theme that enables the action bar. The\
default theme, Theme.Holo, includes the action bar automatically. All action buttons and those\
available in the Action Overflow are defined in an XML menu resource, at res/menu. Declare action\
buttons with the <item> tag.\
When the attribute showAsAction equals \'93ifRoom\'94 that action button will be displayed if there is room\
in the action bar. When it equals \'93never\'94, it will only show in the Action Overflow. All action buttons\
show in the Action Overflow by default unless you specify them to be shown in the action bar I think.\
The icon attribute requires an image in a res/drawable folder.\
To place the menu items on the action bar you need to implement the onCreateOptionsMenu()\
method in the activity to inflate the menu resource in the given Menu object.\
\
Style the Action Bar using Android\'92s style and theme resources. Android includes two baseline activity\
themes that dictate the color of the action bar: Theme.Holo for a dark theme, and Theme.Holo.Light\
for a light theme. Apply these to an entire app or to specific activities in the AndroidManifest.xml using\
the android:theme attribute in the <application> or <activity> tags.\
Create a themes.xml file in the res/values directory of the application package.\
Gotta make sure you make your custom action bar theme inherit from a parent to have use of all the\
normal attributes.\
\
NEED TO LOOK BACK INTO STYLING THE ACTION BAR CUZ IT ISN\'92T WORKING CORRECTLY.\
\
By default the action bar lays on top of the activity, but you can hide it and show it using hide() and\
show() on the action bar, but this causes the device to recompute and redraw the layout based on its\
new size, which is bad. To avoid resizing which action bar hides and shows you can enable Overlay\
Mode for the action bar. This makes the activity use the entire screen and the action bar is overlaid\
on top of the activity, blocking that area, but when the action bar hides and shows up it doesn\'92t\
change the sizing of the screen. Can also make it so the action bar is partially transparent when it is\
there, by styling the action bar.\
To enable overlay mode for the action bar you need to create a custom theme that extends an\
existing action bar theme and set the android:windowActionBarOverlay property to true.\
\
\b Supporting Different Languages:
\b0 \
To work with additional languages create additional values resource files with strings.xml in them\
(i.e. values-es/strings.xml for spanish). You can use the locale qualifier to choose the correct\
language given the user\'92s locale. You can do this for any resource files, in case language isn\'92t the\
only thing you want to change for different locales.\
\
To use a string resource in source code: R.string.stringName\
To use a string resource in an XML file: \'93@string/stringName\'94\
\
\b Supporting Different Screens:
\b0 \
Android categorizes screens using two properties: size and density. Need to include alternative\
resources that optimize the app\'92s appearance for different screen sizes and densities.\
Four Sizes: small, normal, large, large\
Four Densities: low (ldpi), medium (mdpi), high (hdpi), extra high (xhdpi)\
Also may need to revise layout based on screen orientation landscape or portrait.\
Will need to place images in the different drawable resource folders, and also make different layouts\
for different screens.\
Need to create a unique layout XML file for each screen size you want to support. Each layout should\
be put in an appropriate resources directory, for example: res/layout-large/\
Android does automatically scale the layout in order to properly fit the screen, but the reason for\
creating different layouts is in case the layout structure needs to change based on the screen size.\
The file names in each respective layout-size folder must be exactly the same. Don\'92t need to do\
anything in the source code itself as Android automatically chooses the layout files for the user\'92s\
screen size.\
Might need to make different layout files for landscape vs. portrait. Portrait is the default layout style.\
Make a new folder for landscape in the res/ directory like so: layout-land/\
Need to combine orientation and screen size layout files like so: layout-large-land/\
\
To create different bitmaps for different screen densities you should do this by starting with the raw\
bitmap resource in vector format?? (to be held in the res/raw folder) and generate images for each\
density using this scale:\
xhdpi: 2.0\
hdpi: 1.5\
mdpi: 1.0 (baseline)\
ldpi: 0.75\
This means that if you generate a 200x200 image for xhdpi devices, you should generate the same\
resource in 150x150, 100x100, and 75x75, and place all of them in the appropriate folders. Anytime\
you reference the drawable image the system will automatically pick the correct bitmap based on the\
user\'92s screen density. Note: low-density (ldpi) resources aren\'92t always necessary because the system\
automatically scales hdpi resources down by one half to fit ldpi screens.\
\
\b Supporting Different Android Platforms:
\b0 \
In the AndroidManifest.xml file you can choose the minSDKVersion and the targetSDKVersion in the\
<uses-sdk> tag. The target SK version should always be the newest version of Android.\
Android provides a unique code for each platform version in the Build constants class. Use these\
codes in the source code to build conditions that ensure the code that depends on higher API levels is\
only executed when those API\'92s are available on the system. This is what the if-statement was in the\
ActionBar thing where it said do the action bar if the sdk version is 11 or up. In XML though you can\
safely use attributes that are only available on higher sdk versions because Android ignores XML\
attributes that aren\'92t supported by the current device.\
Android provides UI themes for each of its OS versions. By using these build in styles and themes\
you can make an app naturally follow the latest look and feel of Android with each new release. Do\
this in the AndroidManifest.xml file by doing the following:\
To make the activity look like a dialog box:\
<activity android:theme=\'93@android:style/Theme.Dialog\'94>\
To make the activity have a transparent background:\
<activity android:theme=\'93@android:style/Theme.Translucent\'94>\
To apply your own custom theme defined in /res/values/sytles.xml:\
<activity android:theme=\'93@style/CustomTheme\'94>\
To apply a theme to the entire app:\
<application android:theme=\'93@style/CustomTheme\'94>\
\
\b Activity Life Cycle:
\b0 \
An activity can exist in only three states of the Activity life cycle for any extend period of time. These\
are the Resumed, Paused, and Stopped state. Resumed is when the activity is in the foreground and\
the user can interact with it - the running state. Paused is when the activity is partially obscured by\
another activity, the other activity that is in the foreground is semi-transparent or doesn\'92t cover the\