How to boot, clear cache, kill the process, floating windows single double-click to distinguish, with source code
First, the start-up
Many mobile phone software with boot, sometimes let the software start-up will be very practical. So boot of how to achieve it?By looking after we learned that the boot system will send a broadcast is booted Intent.ACTION_BOOT_COMPLETED, then we only need to customize a BroadcastReciever receiving this broadcast, to start the program after receiving a broadcast boot can be achieved.
Example this program MyBroadcastReceiver:
publicclassMyBroadcastReceiverextendsBroadcastReceiver {
@Override
publicvoidonReceive (Context context, Intent intent){
String action=intent.getAction ();
if(action.equals (Intent.ACTION_BOOT_COMPLETED)){
//whether selected boot
booleanstart =PreferenceManager.getDefaultSharedPreferences (
context). getBoolean (
CleanerActivity.KEY_START_WHEN_BOOT_COMPLETED,true);
if(start){
Intent i=newIntent ();
i.setClass (context, FloatService.class);
context.startService (i);
}
}
}
}
AndroidManifest.xml in the following statement:
<receiver android:name = "MyBroadcastReceiver">
<intent-filter>
<action android:name = "android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Second, clear the cache
Used in the source code of Android in Settings the PackageManager's deleteApplicationCacheFiles ()method to clear the cache, but as a third-party software to use this great function difficulty, we in PackageManager found freeStorageAndNotify ()method can also clear the cache, and third-party software use is relatively easy. Therefore, we use freeStorageAndNotify ()method to achieve the cleanup of the cache.
FreeStorageAndNotify ()declared in AndroidManifest.xml permission
<!- This permission is required to clear the cache ->
<uses-permission android:name = "android.permission.CLEAR_APP_CACHE"/>
The specific use of the function in reference source MyFloatView.java clearCache ()function.
Third, kill the process
We provide in ActivityManager.java killBackgroundProcesses (String packageName)function to kill processes specifically how to kill the process can be the reference source MyFloatView.java killBackgroundProcess ()function. The kill process needs in AndroidManifest following statement permissions
<!- need the permission to kill the process ->
<uses-permission android:name = "android.permission.KILL_BACKGROUND_PROCESSES"/>
, Suspended the window double-click
There are many online suspended window tutorial, but very few people the suspended window click and double-click the event. The program by adding a flag to record the time when the user clicks on the floating windows, multi-threaded (using Timer and TimerTask)to judge click and double-click-click and double-click response. The MyFloatView.java onTouchEvent ()function, double-click single judge.
To distinguish single double-click, is achieved by determining the interval of two clicks. Sleeping wait to determine whether the double-click, click event corresponding thread for a certain time prior to execution thread function responses according to the flag bits to determine whether the execution perform click.
Statistical RAM memory size available
A:the Android MemInfoReader class by reading/proc/meminfo related to the function of the memory size, but the third-party programs can not call, we will MemInfoReader.java copy directly to the project and can be used with appropriate modifications.
B:through MemoryInfo and ActivityManager available Ram memory size
ActivityManager am = (ActivityManager)this
. GetSystemService (Context.ACTIVITY_SERVICE);
MemoryInfo mi=newMemoryInfo ();
am.getMemoryInfo (mi);//mi.availMem;memory available for the current system
Log.e ("tag", "getMemoryInfo:"+ mi.availMem);