我收到以下錯誤:錯誤:方法XXX是未定義類型ActivityManager
錯誤:方法killBackgroundProcesses(字符串)是未定義的類型ActivityManager
現在我死了肯定ActivityManager包含該方法http://developer.android.com/reference/android/app/ActivityManager.html#killBackgroundProcesses%28java.lang.String%29。
這裏是代碼,請幫我弄清楚我哪裏出錯了?
package com.robosoft.killswitch;
import java.util.List;
import android.app.ActivityManager;
import android.app.ListActivity;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class KillSwitch extends ListActivity {
/** Called when the activity is first created. */
private RunningApplicationAdapter runningApplicationAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RunningAppProcessInfo> RunningApp = am.getRunningAppProcesses();
runningApplicationAdapter = new RunningApplicationAdapter(this, RunningApp);
//setContentView(R.layout.main);
setListAdapter(runningApplicationAdapter);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
RunningAppProcessInfo x = RunningApp.get(pos);
String y = x.processName;
am.killBackgroundProcesses(x.processName); //Error Here!
}
});
}
}
,這適用於API級別8以下的設備和無根設備? – Shouvik 2010-07-26 12:12:57
嘿謝謝你的片段,但我很困惑,我怎麼能用onclicklistener來實現它?我是否將位置解析爲另一個活動並實施此方法或......?感謝你的協助! – Shouvik 2010-07-26 12:14:06
謝謝兄弟!接受的解決方案=) – Shouvik 2010-07-26 14:22:04