《android_快速上手》由会员分享,可在线阅读,更多相关《android_快速上手(81页珍藏版)》请在金锄头文库上搜索。
1、Android: Quick Start Dmitry Lukashev What is the plan? History foo.hello(); / With reflection Class cls = Class.forName(“Foo“); Object foo = cls.newInstance(); Method method = cls.getMethod(“hello“, null); method.invoke(foo, null); Android Architecture Overview Linux Kernel Display Driver Keypad Dri
2、ver Camera Driver WiFi Driver Flash Memory Driver Audio Drivers Binder (IPC) Driver Power Management Libraries Surface Manager Media Framework OpenGL | ES FreeType SQLite WebKit SGL SSL libc Android Runtime Core Libraries Dalvik VM Application Framework Activity Manager Package Manager Window Manage
3、r Telephony Manager Content Providers Notification Manager View System Location Manager Resource Manager Applications Home Contacts Phone Browser NDK / JNI JVM The pc register (program counter) JVM Stack Native methods stacks Heap Method Area VM Thread lass Runtime Constant Pool class files Class lo
4、ader subsystem native method libraries Execution engine Native method interface Dalvik VM Was written by Dan Bornstein Transform class files into DEX It is VM integrated with Linux uses shared memory, mmap for OS without swap space while powered by a battery zygote The Dalvik VM is register-based: f
5、ewer instructions, code units, instructions Verification editor.putType(String key, T value); mit(); Activity.getPreferences() PreferenceManager.getDefaultSharedPreferences(Context ctx) Context.getSharedPreferences(String name, int mode) mPreferences.getType(String key, T defValue); Backup Applicati
6、on Data (android.app.backup 2.2) Perform backup arbitrary data to remote “cloud” storage Easily perform backup of SharedPreferences and files Restore the data saved to remote storage Controlled by Android Backup Manager Extend class BackupAgent and override onBackup() intent.setFlags(Intent.FLAG_ACT
7、IVITY_NEW_TASK); startActivity(intent); NEW_TASK Task Activity 3 affinity=com.gtug.task2 BACK HOME taskAffinity=com.gtug.task2 Task reparenting android:allowTaskReparenting=“true“ | “false“ Task Activity 1 Activity 2 allowTaskReparenting=true affinity=com.gtug.task2 Intent w/o NEW_TASK taskAffinity=
8、com.gtug.task1 No Task with affinity=com.gtug.task2 Task Activity 1 Intent w/o NEW_TASK taskAffinity=com.gtug.task1 Task Activity 2 allowTaskReparenting=true affinity=com.gtug.task2 taskAffinity=com.gtug.task2 Activity 2 View Activity/Task/Process details adb shell dumpsys dump.txt Activities in Cur
9、rent Activity Manager State: * TaskRecord43ddd1e8 #10 A com.test.xxx clearOnBackground=false numActivities=1 rootWasReset=false affinity=com.test.xxx intent=flg=0x10000000 cmp=com.test.TestUI/.Activity1 realActivity=com.test.TestUI/.Activity1 lastActiveTime=15088595 (inactive for 5s) * Hist #4: Hist
10、oryRecord43ddd000 com.test.TestUI/.Activity1 packageName=com.test.TestUI processName=com.gtug.test123123 launchedFromUid=10025 app=ProcessRecord43d5a1a8 293:com.gtug.test123123/10025 Intent flg=0x10000000 cmp=com.test.TestUI/.Activity1 frontOfTask=true task=TaskRecord43ddd1e8 #10 A com.test.xxx task
11、Affinity=com.test.xxx realActivity=com.test.TestUI/.Activity1 base=/data/app/com.test.TestUI.apk/data/app/com.test.TestUI.apk data=/data/data/com.test.TestUI labelRes=0x7f040001 icon=0x7f020000 theme=0x0 stateNotNeeded=false componentSpecified=true isHomeActivity=false configuration= scale=1.0 imsi=
12、310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 launchFailed=false haveState=false icicle=null state=RESUMED stopped=false delayedResume=false finishing=false keysPaused=false inHistory=true persistent=false launchMode=0 fullscreen=true visible=true frozenBeforeDestroy=false thumbnail
13、Needed=false idle=true Activity launch modes (1) standard android:launchMode=“standard“ | “singleTop“ | “singleTask“ | “singleInstance“ singleTop singleInstance singleTask Multiple instances in one Task Single instance in one Task only one Activity in the Task Activity launch modes (2) Task Activity
14、 1 standard Task Activity 1 Activity 2 Task Activity 1 Activity 2 Activity 3 Task Activity 1 Activity 2 Activity 3 Activity 2 singleTop Task Activity 1 Activity 2 Task Activity 1 Activity 2 Activity 1 Task Activity 1 Activity 2 Activity 1 Activity1 is singleTop onNewIntent() run Activity1 Activity l
15、aunch modes (3) singleTask Task Activity 1 Activity 2 Activity 3 Activity1 is singleTask Task Activity 1 run Activity1 singleInstance Activity1 is singleInstance Task1 Activity 1 no more Activities in this task Task2 Activity 2 run Activity2 Activity Graph of Life Start Stop onCreate() onStart() onR
16、esume() onRestart() onDestroy() onPause() onStop() Kill process Running partly visible foreground no longer visible foreground onPostCreate () onPostResume() Fragments Android Architecture Overview findViewById(R.id.my_button); Layout Parameters layout_something layout parameter Every ViewGroup class implements a nested class that extends ViewGroup.LayoutParams layout_width and layout_height are required for all v