1.Activity related. Launchmode,onsaveinstncestate, life cycle and so on.
4 default Launchmode, and Onnewintent callback.
Onnewintent->onrestart->onstart->onresume
Onactivity->onresume.
Onnewintent, Onactivityresult?
Onnewintent Launchmode with Singletask or singleinstance.
But if set these the mode. Onactivityresult'll is called after Startactivityforresult directly.
So Normally,they can not called both.
Onsaveinstancestate:
There is a description of the activity in this way: when the activity is going to be killed, the system will open up this excuse for the programmer to call
It then passes the bundle information into the OnCreate & bundle.
This method must be called before OnStop, but the order of OnPause cannot be determined.
In some cases, the life cycle does not go to OnDestroy, but some resources need to be released. At this time, it is best to be event driven.
2.Fragment Related technologies.
Fragment life cycle: Android Four components of activity & Fragement
Fragment and activity communication,
Fragmentmaneger.findfragmentbyid
Fragmentmaneger.findfragmentbytag,
Communication between the fragment, Setargument.
Getactivity & AddListener and so on.
Data storage and recovery. The func of the onsaveinstancestate:fragment is synchronized with the activity.
Fragmenttransaction transaction = Fm.bengintransatcion ();//Open a transaction
Transaction.add ()
Add a fragment to the activity
Transaction.remove ()
Remove a fragment from the activity, if the removed fragment is not added to the fallback stack (which is detailed later in the fallback stack), the fragment instance will be destroyed.
Transaction.replace ()
Replace the current with another fragment, which is actually the fit of remove () and then add () ~
Transaction.hide ()
Hides the current fragment, is only set to invisible, and does not destroy
Transaction.show ()
Show previously hidden fragment
Detach ()
The view is removed from the UI, unlike remove (), where the state of the fragment is maintained by Fragmentmanager.
Attach ()
Rebuilds the view view, attaches to the UI, and displays.
Transatcion.commit ()//Commit a transaction
Note: Common fragment buddies may often encounter such an activity state inconsistency: loss this error. The main reason is that the commit method must be called before Activity.onsaveinstance ().
Above, basically is the operation fragment all way, in one transaction opens to commits can carry on the multiple addition, the removal, the substitution and so on operation.
It is worth noting that if you like to use fragment, be sure to understand these methods, which will destroy the view, which will destroy the instance, which is just hidden, so that you can better use them.
Other questions: Android Fragment Real full parsing (bottom)
Fragmenttransaction.addtobackstack (String): If it is the Replace method, then the current fragment will be removed, all back, fragment state will not be preserved, will only re-
Create. And if it's the Hide & Add method, the previous fragment will be re-attch.
If activity manages fragment, you can call all the public methods of fragment.
Findfragmentbyid & Findfragmentbytag can be used to locate fragment, and then ibid.
Fragment can obtain an instance through getactivity.
When the screen is rotated, fragment is created repeatedly, which is the time to determine if the OnCreate bundle parameter is used for the first time.
The default implementation bundle parameter for activity is content.
3. Serialization technology, Parcable & Serializable.
Android interprocess communication Data (i)------The origins of parcel
Why serialize: In order to communicate across processes, interprocess communication is the binary format, so serialization can be reversed by deserializing the data.
Parcable is a memory-machine serialization, so the speed is fast.
Use of 4.fastJson & Gson
PackageCom.joyfulmath.publibrary.json;ImportCom.alibaba.fastjson.JSON;ImportCom.joyfulmath.publicutils.utils.TraceLog;/** * @authorDeman.lu *@versionon 2016-03-24 17:20 * Use Fastjson to resolve the problem*/ Public classJsonutils { Public Static<T> T parseobject (String jsonstr, class<t>Entityclass) {T ret=NULL; Try{ret=Json.parseobject (Jsonstr,entityclass); }Catch(Exception e) {TRACELOG.E ("Parseobject-something Exception with:" +e.tostring ()); } returnret; } Public Staticstring tojsonstring (Object obj) {string ret=NULL; Try{ret=json.tojsonstring (obj); } Catch(Exception e) {e.printstacktrace (); } returnret; }}Fastjson
5. Multithreading-related, including Handler,message Looper. Executorservice.
Message mechanism: Android process/thread management (i)----the framework of the message mechanism see this series.
Executorservice: The thread pool, which can provide shutdown operations, wait for shutdown and direct shutdown.
6.ImageLoader principles, including Glide,picasso, and fresco.
Picasso,square company produced a picture loader, internally using OKHTTP to perform network requests.
can support Url,file, database and other path loading. The picture does not scale,
Picasso & Glide
First, Glide is a two-time development based on Picasso.
With parameters: Glide can use activity, fragment, and so on. So its loading can be tied to the actiivty life cycle.
Glide default Picture argb_565 piocasso:argb_8888
Glide loading Gif but Picasso cannot. But Glide would using much memory with GIF.
Glide'll cache with a size of imageview, so each size of ImageView would contains one copy.
Picasso would only have one CAHCE copy with Fullsize. So glide is faster than Picasso.
Glide helps reduce the occurrence of oom.
/***/Publicinterface iimageloader {void Initloader (context context); void int int height); void Load (String path, ImageView view);}
Iimageloader
Public classImageloadmanger {PrivateIimageloader Iimageloader =NULL; Private StaticImageloadmanger sinstance =NULL; Public Static synchronizedImageloadmanger getsinstance () {if(Sinstance = =NULL) {sinstance=NewImageloadmanger (); } returnsinstance; } /*** InitManager *@paramContext Context*/ Public voidInitManager (Context context) {Iimageloader=NewPicassoimageloader (); Iimageloader.initloader (context); } /*** Load image with path *@paramPath Path *@paramImageView ImageView*/ Public voidLoad (String path, ImageView ImageView) {if(NULL==Iimageloader) { Throw NewRuntimeException ("InitManager have not been init"); } iimageloader.load (path, imageView); } /*** Load image with path *@paramPath Path *@paramImageView ImageView *@paramWidth Width *@paramHeight Height*/ Public voidLoad (String path, ImageView ImageView,intWidthintheight) { if(NULL==Iimageloader) { Throw NewRuntimeException ("InitManager have not been init"); } iimageloader.load (path, imageview,width,height); }}Imageloadmanger
Public classPicassoimageloaderImplementsIimageloader {Picasso Picasso; Context context; Private voidInit () {Picasso=NewPicasso.builder (context). build (); } @Override Public voidInitloader (Context context) { This. Context =context; Init (); } @Override Public voidLoad (String path, ImageView view,intWidthintheight) { if(NULL==path) { Throw NewRuntimeException ("URI is null!"); } if(width = = 0 | | height = = 0) { Throw NewRuntimeException ("width & height is 0"); } picasso.load (path). Resize (width, height). into (view); } @Override Public voidLoad (String path, ImageView view) {if(NULL==path) { Throw NewRuntimeException ("URI is null!"); } picasso.load (Path). into (view); }}Picassoimageloader
Glide 500k,picasso 100K
Fresco is Facebook's open-source picture loading framework. Its use is based on the view level. Simpledraweeview
Fresco, Image Pipline technology, level three cache. So it's not easy to oom.
First floor. Bitmap cache: On 5.0, use Java heap,5.0, use Ashme memory, reduce the probability of GC occurrence.
The bitmap cache is emptied when the app is in the background.
Second layer, memory cache. Store the original compressed picture.
The third layer, the disk cache, will not be emptied.
Fresco has a great effect on memory savings, especially low-end machines, which can reduce the chance of oom.
The package is larger and more complex to use.
7.Adapter and ListView combination.
8. User cookie design. The token process includes the login process.
Landing design:
1) Login Jump
The first is to login to the specified page, such as Mainactivity,
There is a landing, back to the previous page.
These 2 need to be taken into account at the time of landing.
2) Login Password verification
The password is encrypted after transmission, in the form of parameters.
The API uses HTTPS requests.
After the successful landing, you need to save the userinfo to the local, so that after exiting, you can automatically login.
3) Automatic Login
Token mechanism. Once the login is successful, a token message is saved locally, and token can save the outdated information mechanism.
After token expires, all first-off APIs (which need to verify token information) will return the same code information and then be processed uniformly.
Pop-up Alertdialog, let the user to determine whether need to login.
9. Encapsulation of network requests.
Volley
Volley+okhttp
Retrofit
Among them, Retrofit+okhttp+picasso is a unified production of square company.
The mainstream of the routine is to separate each frame so that it is easy to replace.
Retrofit+okhttp/volley+okhttp Add Fastjson, Glide/fresco + buttnkinfe/dragger2/androidannotation + Rebotim.
The first day of Android Framework Learning Okhttp & Retrofit
10.Android & H5 interaction.
H5 Call the Andoriod code:
Websettings.setjavascriptenabled (TRUE);
Mwebview.addjavascriptinterface (New Demojavascriptinterface (), "demo");
JS Callback, @JavascriptInterface
Android Call JS
Mwebview.loadurl ("Javascript:wave ()");
Jump protocol:
When JS callback, can be in the time of shouldoverrideurlloading
Configure the URL as a protocol.
11. Code obfuscation.
Confusing opening: Androidstudio:
Inside the Gradle, there are
buildtypes { release { false proguardfiles getdefaultproguardfile (' Proguard-android.txt '), ' Proguard-rules.pro ' } }
The key is minifyenabled programming true, and confusing compilation will open.
General need to configure Proguard-rules.pro
PROGUARD4 Large Process:
compression, byte-code optimization, obfuscation, preflight.
Proguard can configure the version:
Proguard is inside the SDK.
Proguard can configure the process:
-dontshrink does not compress the input class file
-dontoptimize does not optimize the input class file
-dontobfuscate does not confuse the input class file
12.android Packaging mechanism
Includes commands for the SDK.
Android principle Secret APK build process
Packaging process: AAPT is used to generate resource files R.java
The Java compiler->class file, and then Dex compiles the. dex file.
AAPT placed resource
Packaged as an apk file.
The others will eventually generate the Dex file. +sign process, is the APK, of course, may need compression optimization.
13. The ability to analyze and repair on-line crash.
First of all, for crash where there is no processing, the log is processed and collected through Uncaughtexceptionhandler.
Three steps:
Collect logs and send to server
Prompt user to process
Save to SD
The proguardmapping file needs to be saved so that the online app can analyze the problem.
14. Memory leaks, including memory optimization, memory leak scenarios, and use of the mat tool.
See Android Advanced face questions and answers
15.Monkey mechanism. Android Development How to test an app for monkey.
Monkey is to send random events to the screen, the general number of times are more than 1W, the main test results are CRASH,ANR events.
Monkey object is apk
The monkey event flow is random.
Monkey's Documentation: http://developer.android.com/guide/developing/tools/monkey.html
16. Debugging tools, including debugging features for Ddms,android Studio.
Androidstudio Tools:
Androidmonitor:startmethodtracing test method Execution time.
DDMS also have TraceView, the function is the same.
Test the layout of the view: Hierachyviewer.
Debug: Advanced Debugging Features:
Evaluate Expression: Under the Run menu, this option has the same function as watch, but it can test execution statements.
Conditional breakpoint: In the loop, you are only interested in i=9, what do you do, in the location of the breakpoint, right-click, the condition appears.
Log breakpoint: Also a very useful skill, when we need to print the log in some cases, but each time the compilation is very time-consuming, this time, we have a practical log breakpoint, can print the log, and
The source code is not modified. You can see the printed log in the console inside the debug window.
Method Breakpoint: The method breakpoint is the same as in the function name, the breakpoint, which will be at the function entry and end of the place breakpoint.
Exception breakpoint: Is Run->view blockpoint->javaexception.
Attribute breakpoints: It is difficult to find a multi-threaded complex environment when a property is modified or accessed. Run->view blockpoint->javafieldwatchpoints.
How do I use the DDMS tool in Ddms:android Studio?
17. Unit testing, JUnit's use, including other test frameworks.
Public classExampletest extends Instrumentationtestcase { Public voidtest () throws Exception {finalintexpected =1; FinalintReality =1; Assertequals (expected, reality); } Public voidtest_2 () throws exception{finalintexpected =2; FinalintReality =3; Assertequals (expected,reality); }}
Need to be configured inside the configration.
18.GIT advanced Features, Stage,rebase,revert,stash,cherry Pick & Sub Module
Stage is the index area, a concept that corresponds to the work area and the history area
revert: A history is submitted to cancel, but its commit record will be retained, that is, can be submitted to the remote library.
Reset: Just fallback history, fallback content can be kept in the work area.
Cherry Pick:branch2 on a change, need to merge to Branch3, but I just need this one modification, with this command.
Sub module: The use is not very large.
19. Plug-in programming.
Open a lecture
20. Design patterns, familiarity with common design patterns.
TBD.
21. Heat Repair Technology.
TBD.
22.React +native Frame
TBD.
23. Message Push principle
TBD.
Android Face questions and Answers (2)