I want to show the list of running processes with the help of android program.But it's not showing anything.What to do?? The code is given below:
MainActivity.java:
package com.sysinfo.procinfo;
import java.util.List;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.Toast;
/**
* Starting point of the app. This class will show the list of currently running
* process.
*
* @version 1.0 29-01-2015
*
*/
public class MainActivity extends Activity {
private ListView mProcessListView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
loadProcessInfo();
}
private void initViews() {
mProcessListView = (ListView) findViewById(R.id.processListView);
}
/**
* Get the list of currently running process.
*/
private void loadProcessInfo() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<runningappprocessinfo> runningProcesses = manager
.getRunningAppProcesses();
if (runningProcesses != null && runningProcesses.size() > 0) {
mProcessListView
.setAdapter(new ListAdapter(this, runningProcesses));
} else {
Toast.makeText(getApplicationContext(),
"No running process found.", Toast.LENGTH_LONG).show();
}
}
}
ListAdapter.java
package com.sysinfo.procinfo;
import java.util.List;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
/**
* The adapter to handle the data in list.
* @version 1.0 29-01-2015
*
*/
public class ListAdapter extends ArrayAdapter<runningappprocessinfo> {
private Context mContext = null;
private List<runningappprocessinfo> mProcessList = null;
public ListAdapter(Context context, List<runningappprocessinfo> values) {
super(context, R.layout.list_item_process, values);
this.mContext = context;
this.mProcessList = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list_item_process, parent,
false);
TextView appName = (TextView) rowView.findViewById(R.id.processName);
appName.setText(mProcessList.get(position).processName);
return rowView;
}
}
activity_process_info.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProcessorInfoActivity" >
<textview>
android:id="@+id/View2"
android:layout_width="wrap_removed"
android:layout_height="wrap_removed"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:lineSpacingExtra="10dp"
android:text="Processor Info."
android:textSize="30dp"
android:textStyle="bold" />
<listview> android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/View2"
android:layout_marginLeft="38dp" >
It is compiling the code and when running on emulator,it shows only the heading Process Info and rest of the page blank.Where my code is lacking?