我的用戶界面僅在4.0中被阻止*使用子句:「Runtime.getRuntime().exec(」cat proc/meminfo「);」。 下面的代碼有什麼問題嗎? 在此先感謝。爲什麼運行時在Android 4.0/4.0.3中被阻止?
登錄:
03-27 13:37:18.545: I/MyActivity(19730): ini().429: 1332826638549
03-27 13:37:18.545: I/MyActivity(19730): ini().434: 1332826638549
03-27 13:37:18.865: D/dalvikvm(19611): GC_CONCURRENT freed 389K, 6% free 9733K/10311K, paused 1ms+2ms
代碼:
Log.i(getClass().getName(), "ini().434: " + System.currentTimeMillis());
try {
Process process = Runtime.getRuntime().exec("cat proc/meminfo");//! hang here
Log.i(getClass().getName(), "ini().436: " + System.currentTimeMillis());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
Log.i(getClass().getName(), "ini().438: " + System.currentTimeMillis());
String str = bufferedReader.readLine();
totleMemory = Long.parseLong(str.replaceAll("\\s+", "").replaceAll("[a-zA-Z]", "").replaceAll(":", ""));
Log.i(getClass().getName(), "ini().441: " + System.currentTimeMillis());
totleMemory *= 1024;
} catch (Exception e) {
}
Log.i(getClass().getName(), "ini().446: " + System.currentTimeMillis());
MasterJB,謝謝你們一樣。 – thecr0w 2012-04-05 03:10:46
順便說一句,你是否同意這種說法:因爲有三個流(stdin,stdout,stderr),我們可以通過1.getErrorStream()獲取2。getInputStream()3.getOutputStream(),並且只有在錯誤流完成後纔會獲得輸入流,如果發生某些意外錯誤。或者會有阻塞,是這樣嗎? – thecr0w 2012-04-05 03:21:01
我不確定我是否只爲我的應用程序使用了InputStream。你仍然有錯誤,或者你在做更多的研究嗎? – 2012-04-05 03:23:31