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;
}
}
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!!
In this line
you are casting a List into a CharSequence. Try something along these lines: