• How to achieve the boot, clear cache, kill the process, floating windows single double-click to distinguish, with source


    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);
     
  • 相关阅读:
    HDU 3874 Necklace 区间查询的离线操作
    POJ 1651 Multiplication Puzzle (区间dp)
    POJ 2528 Mayor's posters(离散+线段树)
    POJ 2886 Who Gets the Most Candies?
    webgl教程
    GL_ARRAY_BUFFER 和 GL_ELEMENT_ARRAY_BUFFER
    几个不错的webgl教程网
    svg图标库
    sublime text nodejs set
    图形学着色器学习
  • 原文地址:https://www.cnblogs.com/anfflee/p/3228041.html
Copyright © 2020-2023  润新知