午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    安卓開發(fā)之調(diào)試實例
    來源:易賢網(wǎng) 閱讀:829 次 日期:2014-08-21 16:09:14
    溫馨提示:易賢網(wǎng)小編為您整理了“安卓開發(fā)之調(diào)試實例”,方便廣大網(wǎng)友查閱!

    package AndroidApi;

    import android.util.Log;

    class Monitoring implements Runnable

    {

    public void run()

    {

    while (!Thread.currentThread().isInterrupted())

    {

    try

    {

    Thread.sleep(100);

    } catch (InterruptedException s)

    {

    Thread.currentThread().interrupt();

    }

    AndroidDebug.printVaryMemory();

    }

    }

    }

    public class AndroidDebug

    {

    private static boolean m_bIsDebug = false;

    /**

    * 設置調(diào)試模式

    *

    * @param bIsDebug

    */

    public static void setMode(boolean bIsDebug)

    {

    m_bIsDebug = bIsDebug;

    }

    /**

    * 是否調(diào)試模式

    * @return

    */

    public static boolean isDebug()

    {

    return m_bIsDebug;

    }

    /**

    * 打印信息

    *

    * @param strTxt

    */

    public static void println(String strTxt)

    {

    if (m_bIsDebug)

    {

    System.out.println(strTxt);

    }

    }

    /**

    * 打印信息

    *

    * @param strTxt

    */

    public static void Log(String strTag, String strTxt)

    {

    if (m_bIsDebug)

    {

    Log.i(strTag,strTxt);

    }

    }

    /**

    * 強制回收垃圾,可用于檢測析構函數(shù),檢測未使用對象是否有

    */

    public static void gc()

    {

    if (m_bIsDebug)

    {

    System.gc();

    }

    }

    /**

    * 打印堆總量

    */

    public static void printTotalMemory()

    {

    Runtime r = Runtime.getRuntime();

    AndroidDebug.println("Total memory is :" + r.totalMemory());

    }

    /**

    * 打印堆剩余量

    */

    public static void printFreeMemory()

    {

    gc(); // 執(zhí)行強制回收以獲得準確的剩余量

    Runtime r = Runtime.getRuntime();

    AndroidDebug.println("Free memory is :" + r.freeMemory());

    }

    /**

    * 打印堆變化量

    */

    static long longPre = 0;

    public static void printVaryMemory()

    {

    gc(); // 執(zhí)行強制回收以獲得準確的剩余量

    Runtime r = Runtime.getRuntime();

    long longNow = r.freeMemory();

    if (longNow > longPre)

    {

    AndroidDebug.println("Free memory -> :" + (longNow - longPre));

    longPre = longNow;

    } else if (longNow < longPre)

    {

    AndroidDebug.println("Free memory <- :" + (longPre - longNow));

    longPre = longNow;

    }

    }

    /**

    * 監(jiān)控內(nèi)存

    *

    * @param bIsOpen

    */

    private static Thread m_pThread = null;

    public static void setMonitore(boolean bIsOpen)

    {

    if (bIsOpen)

    {

    if (null == m_pThread)

    m_pThread = new Thread(new Monitoring());

    m_pThread.setDaemon(true);

    m_pThread.start();

    }

    else

    {

    if (null != m_pThread)

    {

    m_pThread.interrupt();

    m_pThread = null;

    }

    }

    }

    更多信息請查看IT技術專欄

    更多信息請查看網(wǎng)絡編程
    易賢網(wǎng)手機網(wǎng)站地址:安卓開發(fā)之調(diào)試實例

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)