Directory
- Customize two view to paint and refresh the redraw individually
- Activity set to Singletop, long press the home button to start the problem
- Activity set to Singletop, long press the home button to start the problem
- Android Soft Keyboard Block interface
- Android uses asynctask to download pictures, preferably using weakreference
- Android webview Load Network Video
- Network download policy and file cache policy in Android development
- The Addfooterview of the ListView in Android does not display the issue
- Android Auto Eject soft keyboard
Customize two view to paint and refresh the redraw individually
I divided the screen into left and right parts, and I customized the drawing classes Drawoneview and Drawtwoview, which inherit the view class, where Drawoneview is displayed on the left side of the screen, Drawtwoview on the In Drawoneview it is possible to redraw it through the invalidate () function, but in Drawtwoview it is not possible to redraw drawtwoview with the invalidate () function. and when the Drawoneview to redraw, how will also drive the Drawtwoview redraw, they should be separate from the respective classes to control, why this happened?
One with invalidate (), the other with postinvalidate () can refresh the
is to call invalidate (), Postinvalidate () in the place where you need to refresh the UI.
Activity set to Singletop, long press the home button to start the problem
If the activity is set to Singletop, then, after pressing the home key, and then long press the start time, the home key startup mechanism, it seems to restart the activity set to Singletop, Although your singletop activity has finished or the entire program has been completed.
The current solution is to mark and then intercept in the activity that is set to Singletop .
Android Soft Keyboard Block interface
Android:windowsoftinputmode= "Stateunspecified|adjustpan"
Instead of squeezing the screen, you squeeze the interface up.
< activity android:name = ". Activity. Maintabactivity " Android:theme =" @ Android:style/theme.notitlebar " android:configchanges = "Keyboardhidden|orientation" android:screenorientation = "Portrait" Android:launchmode = "Sing Letask " Android:windowsoftinputmode =" Stateunspecified|adjustpan " > </ activity >
It is important to note that if an activity inside the tabactivity has a edittext with a soft keyboard pop-up, the activity setting does not work and needs to be set in tabactivity.
Android uses asynctask to download pictures, preferably using weakreference
Some people like to use Android-provided asynctask, but in fact the asynctask problem is more serious, thread only occurs when the run function does not end the memory leak problem, however The implementation mechanism of the ASYNCTASK internal is the use of threadpoolexcutor, the life cycle of the thread object produced by this class is indeterminate and is beyond the control of the application, so if Asynctask is the inner class of activity, The problem of memory leaks is more likely.
How should the memory leak problem caused by this thread be resolved?
First, the internal class of the thread is changed to a static inner class.
Second, use weak references inside the thread to save the context reference.
The model is resolved as follows:
Public Abstract classWeakasynctask<params, Progress, Result, weaktarget>extendsAsynctask<params, Progress, result> { protectedWeakreference<weaktarget>Mtarget; PublicWeakasynctask (weaktarget target) {mtarget=NewWeakreference<weaktarget>(target); } /** {@inheritDoc} */@Overrideprotected Final voidOnPreExecute () {FinalWeaktarget target =Mtarget.get (); if(Target! =NULL) { This. OnPreExecute (target); } } /** {@inheritDoc} */@Overrideprotected FinalResult doinbackground (params ... params) {FinalWeaktarget target =Mtarget.get (); if(Target! =NULL) { return This. Doinbackground (target, params); } Else { return NULL; } } /** {@inheritDoc} */@Overrideprotected Final voidOnPostExecute (Result result) {FinalWeaktarget target =Mtarget.get (); if(Target! =NULL) { This. OnPostExecute (target, result); } } protected voidOnPreExecute (weaktarget target) {//No Default Action } protected AbstractResult Doinbackground (weaktarget target, params ... params); protected voidOnPostExecute (weaktarget target, result result) {//No Default Action } }
Android webview Load Network Video
Webview.loadurl (Video_url); Webview.setinitialscale (50); WebSettings setting=webview.getsettings (); Setting.setusewideviewport (true); Setting.setjavascriptenabled (true);//Support JavaScriptSetting.setpluginsenabled (true);//Support Plugins, for example just like Flash plugin.Setting.setsupportzoom (true);//Zoom Control on the Web (you don ' t need this if ROM supports Multi-TouchSetting.setbuiltinzoomcontrols (true);//Enable Multitouch if supported by ROMWebview.setwebviewclient (Newmywebviewclient ()); Public classMywebviewclientextendswebviewclient {Privateprogressdialog Loadingbar; @Override Public voidonpagestarted (WebView view, String URL, Bitmap favicon) {Loadingbar=progressdialog.show (Mactivity,NULL, "Loading ..."); Super. onpagestarted (view, URL, favicon);} @Override Public Booleanshouldoverrideurlloading (WebView view, String URL) {view.loadurl (URL); //the links inside the webview are also loaded in the same page return true; } @Override Public voidonpagefinished (WebView view, String URL) {if(Loadingbar.isshowing ()) {Loadingbar.dismiss (); } Super. onpagefinished (view, URL);} @Override Public voidOnreceivederror (WebView view,intErrorCode, string description, String failingurl) {Toast.maketext (mactivity,"Loading Error!" ", Toast.length_long). Show (); FinalAlertdialog Alertdialog =NewAlertdialog.builder (mactivity). Create (); Alertdialog.settitle ("ERROR"); Alertdialog.setmessage (description); Alertdialog.setbutton ("OK",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Alertdialog.dismiss (); } }); Alertdialog.show ();}}
Network download policy and file cache policy in Android development
The general caching policy is:
First-level memory cache, level two file cache (database also counted as file cache), level three network data
a cache policy for network downloads
Basic strategies for network download files (picture, audio, video):
1. Do not download directly to the destination file, you should use the temp file for the relay, To ensure the correctness and completeness of the file, the process is as follows:
a) generate a unique local destination file name B
B) with the network target file name B) generate a unique local temporary file name with local destination file name: T
C) download file to T
D) Download complete, Verify the correctness and completeness of the file T
E) Delete the file T if it is incorrect or incomplete, and return False
F) After the checksum is complete, rename or copy the file T to the B file
G) The last cleanup site, delete the temporary file T, and return true after success
2. Try to provide verification of file correctness and completeness:
a) Correctness: for example Md5/hash Code alignment, file format comparison.
B) Integrity: For example, if the file size is consistent, the image data is correct (information is provided in the header of the picture file)
3. Consider whether the files downloaded to the local need to be processed two times, you can think of the following:
a) For example, the size of the network source image is 800*600, and we need to be a thumbnail size of 160*145, so consider the download after the file is cropped, and then saved, for the source file is deleted directly.
Second, the file cache policy:
1. The corresponding I/O key for a unique cache file is required, and hashcode can generally be used.
2. If the same file, at different times, can be considered, first clear the local cache, and then download the new cache to local.
3. The same file can also be prefixed with a timestamp before generating a unique hashcode.
4. When generating a file, it may be necessary to take the following comprehensive consideration:
A) SDcard whether there is no space (this demand is there, but few people will consider, once it happens, will crash).
b) the cache cleanup policy. Daily, weekly scheduled cleanup? After reaching a threshold, automatically clean it up? (if there is no cleaning strategy, the garbage data has been a treasure one, it is very SB's).
c) Cache the data that is really needed. Do not feel external memory is unlimited, so you can save everything, you know, more and more complex, and chaos. Once a colleague, hundreds of MB of user data per day (all the user's gender, age, contact and so on), and PM need only a daily number of active data reports, and then finally to cache the daily user Analysis report data can (only 10 KB).
d) encrypt the cache file. The simplest is to remove the file extension, which is also encrypted, of course, you can encrypt the server file, and then decrypt in memory. This depends on the needs of the project, my experience is not enough, the general is to change the extension and so on.
Three, memory cache policy
The memory cache policy is designed to handle more efficient caches, which can be slowed down in memory for file data that is not annoying to update, but with the following considerations:
A) memory I/O, weak reference. Weak references allow the JVM to recycle more rationally and autonomously.
b) The key for the memory cache must also be unique and can refer to the file cache key policy.
c) provides an interface for memory cache refreshes. Although the memory cache itself has a shorter life cycle, it must be the topmost user data, so designing a UI refresh interface is a consideration.
The Addfooterview of the ListView in Android does not display the issue
NULL false ); Mlistview.setadapter (mbloglistadapter);
The Addfootview can be settled before the Setadapter is placed.
Android Auto Eject soft keyboard
Add in OnCreate:
// auto-bring soft keyboard Timer timer = new Timer () timer.schedule ( new TimerTask () {@Override public void run () {((Inputmethodmanager) Getsystemservice (Input_method_service)). t Ogglesoftinput ( 0 $);
I'm the dividing line of the king of the Land Tiger.