如何使用getRunningAppProcesses()在android系统? [英] how to use getRunningAppProcesses() in android?
本文介绍了如何使用getRunningAppProcesses()在android系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面这段code的:
i have the following piece of code :
package com.example.task;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainTask extends Activity {
private Button BprocessesShow;
private TextView processesShow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_task);
ActivityManager manager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
final List<ActivityManager.RunningAppProcessInfo> runningProcesses = manager.getRunningAppProcesses();
BprocessesShow=(Button) this.findViewById(R.id.BshowProcesses);
processesShow=(TextView) this.findViewById(R.id.showProcesses);
BprocessesShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
processesShow.setText((CharSequence) runningProcesses);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main_task, menu);
return true;
}
}
以及所有我想要做的是,当用户presses我做了,我想向他出示/她的一切都有他的手机上运行的进程按钮...当我运行这个应用程序我手机应用程序崩溃,我得到的是一个不幸的消息任务(这是我的名字的应用程序)已停止...任何帮助将是非常有用的!
well all i want to do is, when the user presses the button i made i want to show him/her all the running processes that has on his phone ...When i'm running this application on my cellphone the app crashes and all i get is a message Unfortunately Task(that's my name's app) has stopped...Any help would be very useful!!
推荐答案
在此行
processesShow.setText((CharSequence) runningProcesses);
您是铸造一个List成的CharSequence。尝试沿着这些路线的内容:
you are casting a List into a CharSequence. Try something along these lines:
StringBuilder b = new StringBuilder();
for (ActivityManager.RunningAppProcessInfo process: runningProcesses) {
b.append(processs.processName);
b.append("\n");
}
processesShow.setText(b.toString());
这篇关于如何使用getRunningAppProcesses()在android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文