Anda di halaman 1dari 25

2

" , .2013

.
.
, , , , ,
) "" ,(Java ) XP ,Scrum ,Agile(
.Kernel Mode VS User Mode VS User Mode
,:
) . ""?(
1 .
.C++
Debugging.
.


, "" "":
"" , Linkage : .
"" .

M ISRA C
M ISRA Motor Industry Software Reliability Association :
.
MISRA C ) ( .C
, .
142 122 ,2004 20 .
100%
.

. , .
" "
1

, .

C , , =0
,0 ==0 0 ;0 0 if 0'.
:

; )i f ( x==0
; )( doHorribleThings

" "
:C ?
? :

23
0
3
0
12

=
=
=
=
=

5 4 + 3
i =! i > 14
1 << 2 + 4
a & 0x0F <= 0 x07
; a =5; b = a+ ++a

" "
C , .
, int , IN T 16 16.
, :

; ) void f ( i n t a , i n t b
; int i = 1
; ) f ( i ++, i / 2

;) f (i + +, i/2 f (2, 1) : Visual Studio U nix ).f (2, 0


" "
"" ,
) (.
, new bad_alloc ,Visual C++ .N ull
,M icrosof t .ANSI C++
) (http://support.microsoft.com/?kbid=167733 :


C . C"
) ( .
C ,stack overflow ,0
.


" , .
, :
,
,CONSTANT_VALUES_IN_UPPERCASE
,ClassN amesStartsW ithCapitals
,variableN amesStartsW ithLowercase
m_memberVariables
s_staticVariables
"" :Scope
g_globalVariables
)(methodName
MethodName() :
)(method_name

, , , .
, IN OU T .

, :

WRONG:
{ ) i n t Sample ( i n t i n p u t V a l
; ) i n p u t V a l += C u r r e n t F a c t o r ( i n p u t V a l
; ) i n p u t V a l = M u l t i p l i e r ( i n p u t V a l
...
; return i n p u t V a l
}

RIGHT :
i n t Sample ( i n t i n p u t V a l ) {
int l o c a l V a l = inputVal ;
l o c a l V a l += C u r r e n t F a c t o r ( l o c a l V a l ) ;
l o c a l V a l = M u l t i p l i e r ( l o c a l V a l ) ;
...
return l o c a l V a l ;
}

Hungarian Notation " "


: lowercase

ulAccountNum
szName
bBuzy
cApples
iSize

: variable is an unsigned long integer


: variable is a zero terminated string
:
variable is boolean
:
count of items
:
integer or index

! ,
: 3.14159265 r r : , ," "
const int PI = 3.14159265 : ,P I r r

Defensive Programming
, . ,
. .
.Proactive Debugging
: !
, , , . ,
: ? ? ?
, , :
integer : 8, 16, 32 64 , )?.(embedded? 64 bit desktop
sizeof limit.h .
/* Minimum and maximum values a signed char can hold. */
)# define SCHAR_MIN (-128
# define SCHAR_MAX 127 /* Maximum value an unsigned char can hold. (Minimum is 0.) */
)# define UCHAR_MAX 255 # define SHRT_MIN (-32768
)# define SHRT_MAX 32767 /* Maximum value an unsigned short int can hold. (Minimum is 0.
*/
# define USHRT_MAX 65535 /* Minimum and maximum values a signed int can hold. */
# define INT_MIN (-INT_MAX - 1) # define INT_MAX 2147483647 /* Maximum value an
unsigned int can hold. (Minimum is 0.) */
# define UINT_MAX 4294967295U ...
: !
. ,
, , '.
.
: !
. .
.
, .
, :
,
.
, :
? ? ? ,?
? ? ?
:Google . :
!
http://googlestyleguide.googlecode.com/svn/trunk/cppguide.xml :


HandleStuff() :

) (
by ref erence
) (http://www-cs-students.stanford.edu/~sjac/c-to-cpp-info/references :


0
" " ) , e'(
by ref erence ) ! (?by value


) ,(status !
.
, .N ull
.
.malloc,realloc or free
D0 tors .
) (.
: , A || B A .

2
Defensive Programming
, : ,Debugging
. .
: , ' . .
,
.


: !

3
4
5
6
7
8
9
10
Android Programming
) .(Linux Kernel
" ,Google ) Open Handset Alliance 65
(.
' , .Dalvik
' .
JV M ,Native Development Kit, NDK .c/c + +

) (2013

Android Architecture
:
, Kernel , ) .(Drivers etc. ,
, .C/C + + , Dalvik ,
.Dalvik code
.Java Java Byte Code
.Dalvik Code Dalvik ,F ramework Java
.
, .
, :

Native Libraries
,C/C + + .Java
: Surface Manager .

10

:openGL/SGL 2D 3D .GP U
:Media framework (coder decoder) codec
:W ebkit Chrome Saf ari .

Dalvik Virtual Machine Core Libraries


,Dalvik ) embedded ,
(.
dx class ) dex .(Jar dex
byte code .(Dalvik executable)DV M . ,
Jar . Data .
, .
.
(just in time) ,JIT . ,2.0
2.2 .
, , Core Libraries Java ,
.Native Libraries

11

Application Framework
Java .Android
:Activity Manager .
:Package Manger .
:Content providers .

12

Applications
, : .
, ) Home ,Contacts , P hone Browser , (Launcher' .
, ,Java ) (.

13

Android Architectural Pattern


' , main entry
,point , Framework-based architectures ,
, ' .
. ,frameworks , ' ,
, ' .
"" Garbage Collector
,root GU I f oreground
) ( .
.f ront , . "
. , A B ,f oregroung
A .
, lif ecycle
.Activity

14

MVVM Model-View-ViewModel
Design Patten GUI Business
Logic Back end logic .
V iew Data objects .
, V iew M odel .
M F C ,Swing GU I
GU I.
" :
GU I " GU I , .XM L
GU I " V iewM odel " ."V iew "
) (Binding A )( . onButtonAClick
"".


: ,
5 ,
) ,(manif est :
.

Android 101
:Activity . ) (U I .Activity .Activity
, Activity . Activity
, , .
:ActivityManager Activities .
Activities .
: Intent .
.
:
, " Intent Activity.
.Activities
, , .
' .
Broadcast.

15

:Intent .
) ,(Explicit .
) , (Implicit , " Intent Filter
. , .
: Service , .U I
,Activity ,U I ,Service Intent ,
, , '.
: Content Providers .
: , (DB) SQLite ,' . content provider
. .ContentP rovider
:Broadcast receivers .system-wide , :
, ' . BroadcastReceiver
.Intent


.
. .
, .

16

17

ActivityService
,Activities , ,Services ,
.
Service lifecycle

Activity lifecycle

, " .Override
.
onResume :onStart onResume Activity
.onStart Activity ,
.onStart Activity , .onResume
onStop , onP ause :onResume Activity ,
Activity .onP ause Activity , .onStop
onResume " Activity .
back Activity , Activity
. Activity ,onP ause onResume
. Activity onP ause onStop
, Activity onCreate onStart.onResume
onStop :onDestroy onStop Activity .
onDestroy , .Activity
Activity , .

18

:onCreate .
,2 .

Home ,Gmail ,inbox .


. ,
) .(M aps .
, 2 : System Process Activity Manager
Activities ,Home Activity :

:gmail state Home Activity Manager


M ail , Activity :

: state Mail List M ail


:

Activity ,

19

:state Browser
Activity Browser :

: state Browser .
M aps !

,Home .
Browser , M ail :

20

:M aps Activity M aps :

back : Activity M aps


.Browser state .Browser

21

back : M aps , .M ail


M essage state .Activity Manager Activity
Browser :

back : .Mail List state


Activity Manager M essage :

22


:Android

23

View .GUI widgets


, .GUI widgets " )(
GU I . " (XML GUI definition, (layout file)) XM L ""
) (inf lated , .
Activity , . ,
V iewM odel M V V M . Activity
,GUI layout , . , ,Activity
. Activity ,
) (state:
Active and running GU I) f oreground : (Activities
Paused GU I . .
Stopped GU I . .
(interf ace) ContentProvider
.M V V M , SQLite ,
.(i.e: file:///home/username/books/ ) Uniform resource identifier :U RI ,
ContentP rovider DB .
, )( query ,ContentP rovider ) Cursor
ResultSet , (JDBC .
Service ,
.ContentP rovider
:Service
: , Activity .f oreground GU I Activity
Activity ,
.
: ?f oreground
,Activity ContentP rovider
Activity ,.
Service . .f oreground
, Activity , Service
, Activity.
BroadcastReciever "" publish/subscribe
) (RSS " .
Intent ,
.

24

Android Manifest
XM L :
Java Package . )(Unique ID
:Services, Activities, ContentP roviders, BroadcastRecievers
' ," .
.
AP I .
Android API ) (.
.

Resources
, XM L ,GU I XM L
.
' resouces " . ,
resource . , package ,resources
.R ) f inal ( .
.

Files
: ,DB (Opaque Binary Blob) OBB
file systems , .cached files AP Is , "
) Context Service.(Activity

11
12
13

25

Anda mungkin juga menyukai