通过应用Drop_caches不起作用 [英] Drop_caches by app doesn't work
本文介绍了通过应用Drop_caches不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了这个剧本,但不工作:
I've made this script but doesn't work:
package com.mkyong.android;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import java.io.IOException;
import com.example.toast.R;
public class MainActivity extends Activity {
private Button button;
public void onCreate(Bundle savedInstanceState) {
final Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("su");
}
catch (IOException e) {
e.printStackTrace();
}
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@SuppressLint("SdCardPath")
@Override
public void onClick(View arg0) {
final Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("echo 3 > /proc/sys/vm/drop_caches");
Toast.makeText(MainActivity.this, "Script lanciato con `successo, memoria svuotata.", Toast.LENGTH_LONG).show();`
}
catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
不会释放RAM内存:(而是通过终端模拟器goes..If我试图改变命令,例如,做一个目录与MKDIR去,去一个TXT文件,甚至写作..有什么不对?
Doesn't free the RAM memory :( but via terminal emulator goes..If i try to change command and for example, make a dir with mkdir goes, goes even the writing of a file txt.. what's wrong?
推荐答案
您可以试试这个。
try {
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "echo 3 > /proc/sys/vm/drop_caches" });
proc.waitFor();
} catch (Exception e) {
Log.d("Exceptions", "Exception dropping caches: "+e);
}
或
Process p=null;
try {
p = new ProcessBuilder()
.command("PathToYourScript")
.start();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(p!=null) p.destroy();
}
这篇关于通过应用Drop_caches不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文