1. The function of the suspended form is implemented :
1.1. Application Uninstall : Package Installer Packageinstall, package uninstall Packageruninstall
Intent.setdata (Uri.pare ("package:" + App bundle name ))
Remember to update the list collection and update the adapter When you are done uninstalling .
However, you are not sure whether the user has ordered the uninstallation , so you need to get the message through the broadcast .
and need to register through code , because this broadcast only takes effect in application management .
Remember Adddataschme ("package")
After receiving the broadcast , Update the set of appropriate adapters , Remember to turn off the broadcast
Exception : concurrentmodificationexception, Concurrent Access exception error
Because an enhanced for loop is used to remove elements from the collection , Concurrency modification exceptions occur .
Additional : the system application is not allowed to uninstall, so traverse the user application collection is possible .
1.2. Application opening : The essence is to open the app's entry activity.
When an activity manifest file , The intent filter has
<action android:name= "Android.intent.action.MAIN"/>
<action android:name= "Android.intent.category.LANUCHER"/>
Find Relationships and get features .
in packagemanager pm
Intent Intent = pm.getlanuchintentforpackage ( package name )// if the corresponding application activity Configure the properties above and return to the front door activity, if no activity is configured for this property , the return is null;
1.3. Application Sharing function : Open the system's text message , send the message to the friend ( or QQ, , Weibo, etc. )
Some instant Messaging , or social apps , have rewritten shared actions , and if they're shared by SMS , These programs will be listed .
SMS Application , the text message activity,composemessageactivity, according to the following intent filter type , can send different information . have pictures , Video , text .
After setting the intent Property , put the text you want to send to Intent.putextra (intent. Extra_text,.......);
1.4. Application Information features : actually open the system's application information interface
Configuring the installedappdetails of the manifest in the setting system Source
If you do not know how to write intent information , Find a type of software , open it this feature , will appear in the log .
Intent Intent = new Intent ("Android.setting.APPLICATION_DETATLS_SETTINGS");
Intent.addcategory (Intent. Category.default)// Set the default Category
Intent.setdata (Uri.parse ("package:" + pack name ));
2. Process Management
2.1 UI Interface title Reference layout
Activitymanager am Process Manager
① gets the currently running process through the Process manager .
Am.getrunningappprocesses ()// returns the currently running APP Collection
② get the available memory space
Am.getmemoryinfo (Memoryinfo outinfo)// Save the Memory information summary for the parameter ,
Outinfo.avaimem ( system free memory space ). Tatalmem ( Total memory space of the system )
Available memory returns is a Long type and needs to be converted to MB form Formatter
③ Create a new information acquisition class ( Get information on the engine package ):P Rocessinfoprovider
Gets the data for all process information . requires an entity class to hold information )
Reference method name Getrunningprocessinfos ();
Entity class name :P rocessinfo
Information you need to save : application name label, icons icon , memory footprint , application package Name PackageName.
Distinguish between user and system processes ( Judging by user programs or System programs );
gets the collection of running applications through am .
Getrunningappprocesses ();// Returns a collection of running applications ,
Each object info
Info.importance// priority of Process
Info.pid// process ID, Unique identification of the process
Info.processname// process name , which is actually the package name of the application
Other information is used to get the software information application , get the package name >> Get the package information >> get the information you want.
Packagemanager pm
Pm.getpackageinfo ( package name , 0 ( additional optional tag ))// return a package information PackageInfo packinfo
packinfo.applicationinfo.xxxx// The corresponding information .
Am.getprocessmemory (int[]{})//The corresponding multiple process information is returned through a save multiple process pid .
Returns the process information . Gettotalprivatedirty ()// returns the KB, *1024 conversion to byte Convenient calculation .
Finally, each encapsulated object is placed in the list collection and returned to the caller .
The process in the Android system is not app apply , like system, , kernel application , java Span style= "font-family: the song Body;" > c , apk name .
when the package information is obtained through getpakcagerinfo , the process will be abnormal , according to the Catch code block , set a name (packname) and a default picture for it .
Item Entry reference UI
④ other similar application managers, split small collections, add reminders to small entries. Holder optimization, multiplexing convert object, etc.
3 Handle with Tick box listview
If there is a button,check in the list of the focus of the control, the focus will be snatched from the item, which will lead to the ListView item Click event Effect invalidation, generally in the development of the focus of the control clickable = "false", focusable= " False
cannot be clicked, nor will it get to the focus
Adds a checkbox Boolean variable to the process Application object wrapper class to determine if it is selected (and can be saved in a collection, but the user will want the checked application to be checked by default, so it is easier to package)
In the Click event of the ListView, lv.getitemposition (position);//Gets the clicked Item object.
The returned object is null
Because the GetItem () method returns NULL when customizing the adapter, the obtained value is also null
So you can return the clicked object in this method.
In the Click event, get to this object and get to the CheckBox object, then set the corresponding parameter after clicking.
However, there will be a bug that re-uses the historical cache, where you need to add a checkbox variable in the holder to assign the checkbox when the adapter returns to view.
4, process-managed process cleanup
Clean the process after clicking the button.
① loops through the collection to determine whether the process is selected.
② through the Process Manager activitymanager.killbackgroundprocesses (package name);
After the cleanup, you need to refresh the interface and get the data back
③ requires permission: kill_background_proces
5. Details of Process Management
① Select All and reverse:
Select all: Iterate through the collection. Set all to True to notify the data adapter to update the data
Inverse selection: Iterates through the collection, setting all of the original state to reverse, and then updating the data.
Extra: Unable to purge process, system process, system UI process, foreground process, killbackgroundprocess is cleanup background process.
The developer seems to understand, but the user does not understand.
② clean-up effect with one click,
As long as all clean up, the display of all the processes in the interface to clean up (silly users) (360 of the fraud on the market is better, it will even determine your recent cleanup time, if too close, the direct prompt is empty)
After a key cleanup, the user checked the item to remove (saved in a collection kill, easy to display in the last toast)
Toast: Cleans up the kill.size () process, releasing the sum of the elements in Kill that Occupy memory.
Change the title, run the process and the amount of memory in both parameters. You can save them by two member variables
The two parameters are then subtracted from the data in the collection above (minus the number of processes and the total memory consumed).
Remove an entry from the interface, traverse the Kill collection, determine which collection it belongs to, remove it from the collection, and then update the adapter.
Extra: In common sense, the cleanup process should not clear its own application process.
Determine if the returned view is in its own application (as determined by the package name), hide the checkbox check box.
Click on the event, but also to make a judgment, if the match is directly terminated, return the event. Select all, reverse the same, skip the special option.
Wanandroid.com//Android Knowledge Point Summary
Mobile defender 09_ application four kinds of view _listview small title _ Process Management