欧美国产另类久热|951超碰伊人久久|伊人影视久久久久|色婷婷亚洲小电影|色东京热69XX|婷婷玖玖深爱网|加勒比东京热网站|无码A级毛片在线观看|一级a毛一级a看|中文字幕人妻欧美

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

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;

/**

* 設置調試模式

*

* @param bIsDebug

*/

public static void setMode(boolean bIsDebug)

{

m_bIsDebug = bIsDebug;

}

/**

* 是否調試模式

* @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);

}

}

/**

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

*/

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)控內存

*

* @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技術專欄

更多信息請查看網絡編程
易賢網手機網站地址:安卓開發(fā)之調試實例
關于我們 | 聯(lián)系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權所有:易賢網