我在甲状腺中 a一新,我的sis像是甲状腺博士。 我的第1号问题是选择多种应用,一劳永逸地加以杀害。 很抱歉,我已经存在第1点问题,但我的问题是,我只能一次杀手。 因此,我在此感谢您立即回答我的问题:
package plm.thesis.taskkiller;
public class TaskKillerActivity extends ListActivity {
private static final String TAG = "TaskKillerActivity";
TaskListAdapter adapter;
RefreshReceiver receiver;
class RefreshReceiver extends BroadcastReceiver {
private static final String TAG = "RefreshReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "refreshing");
clearRunningProcessesList();
loadRunningProcesses();
}
}
public void clearRunningProcessesList() {
adapter.clearTasks();
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adapter = new TaskListAdapter(this.getApplicationContext());
setListAdapter(adapter);
loadRunningProcesses();
receiver = new RefreshReceiver();
getApplicationContext().registerReceiver(receiver,
new IntentFilter("plm.thesis.taskkiller.REFRESH_RECEIVER"));
}
@Override
protected void onDestroy() {
super.onDestroy();
getApplicationContext().unregisterReceiver(receiver);
}
public void loadRunningProcesses() {
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appinfolist = activityManager
.getRunningAppProcesses();
Log.d(TAG, "AppInfoList Size: " + appinfolist.size());
for (RunningAppProcessInfo runningAppProcessInfo : appinfolist) {
TaskObject runningtask = new TaskObject();
runningtask.pid = runningAppProcessInfo.pid;
runningtask.processName = runningAppProcessInfo.processName;
adapter.addTask(runningtask);
}
}
class TaskObject {
int pid;
String processName;
}
class TaskListAdapter extends BaseAdapter {
private static final String TAG = "TaskListAdapter";
ArrayList<TaskKillerActivity.TaskObject> list;
Context context;
public TaskListAdapter(Context context) {
Log.d(TAG, "created new task list adapter");
this.context = context;
if (list == null) {
list = new ArrayList<TaskKillerActivity.TaskObject>();
}
}
public void addTask(TaskObject taskObject) {
list.add(taskObject);
}
public void clearTasks() {
list.clear();
Log.d(TAG, "list size:" + list.size());
this.notifyDataSetChanged();
}
public int getCount() {
return list.size();
}
public TaskObject getItem(int position) {
return list.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.taskitem, null);
TextView textPid = (TextView) view.findViewById(R.id.taskPid);
textPid.setText(Integer.toString(getItem(position).pid));
TextView textName = (TextView) view.findViewById(R.id.taskName);
textName.setText(getItem(position).processName);
Button buttonKill = (Button) view.findViewById(R.id.taskKill);
buttonKill.setTag(getItem(position).processName);
CheckBox chckKill = (CheckBox) view.findViewById(R.id.appSelected);
chckKill.setTag(getItem(position).pid);
view.findViewById(R.id.taskKill).setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
Log.d(TAG, "killing process: " + v.getTag());
activityManager.killBackgroundProcesses((String) v
.getTag());
context.sendBroadcast(new Intent(
"plm.thesis.taskkiller.REFRESH_RECEIVER"));
}
});
return view;
}
}
}