On android system.I want to get the status of running apps,how to do?
ex. foreground / background!
On android system.I want to get the status of running apps,how to do?
ex. foreground / background!
A quick Google search provided me this article. The basics are:
In your manifest file add the permission:
<uses-permission id="android.permission.GET_TASKS"/>
In your Activity do something like this:
@SuppressWarnings("unchecked")
private void updateTaskList() {
/* Grab the Systems IActivityManager. */
IActivityManager myActivityManager = ActivityManagerNative.getDefault();
/* Will hold all the task"".toString()"" entries */
ArrayList<String> listEntries = new ArrayList<String>();
try {
int showLimit = 1;
/* Get all Tasks available (with limit set). */
List<IActivityManager.TaskInfo> allTasks = myActivityManager
.getTasks(showLimit, 0, null);
int i = 1;
/* Loop through all tasks returned. */
for (IActivityManager.TaskInfo aTask : allTasks) {
listEntries
.add("" + (i++) + ": "
+ aTask.baseActivity.getClassName() + " ID="
+ aTask.id);
}
} catch (DeadObjectException e) {
Log.e("TaskManager", e.getMessage(), e);
}
/* Display out listEntries */
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1_small, listEntries));
}
Please note that I haven't tried this... it's just from that site I linked above.