zoukankan      html  css  js  c++  java
  • 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);
     
  • 相关阅读:
    js 实现长按效果(类似安卓的)
    Java编程思想学习笔记(一)
    中文自然语言处理(NLP)(五)应用HanLP分词模块进行分词处理
    中文自然语言处理(NLP)(四)运用python二维字典和jieba实现词频的统计
    中文自然语言处理(NLP)(三)运用python jieba模块计算知识点当中关键词的词频
    中文自然语言处理(NLP)(二)python jieba模块的进一步学习和xlrd模块
    中文自然语言处理(NLP)(一)python jieba模块的初步使用
    正则表达式(几个例子)
    用户登陆界面(jquery)
    一个简单的注册页面,基于JS
  • 原文地址:https://www.cnblogs.com/anfflee/p/3228041.html
Copyright © 2011-2022 走看看