在android中用什么方法可以获取最近打开过的程序?一直没有思路,请教高人指点!
解决方案 »
- 关于View里的onDraw方法,锁屏、解锁后不执行的的问题
- socket接受结构体并解析问题!
- ******【android调用WCF接口Get Post方式还有ref参数的配置】******
- 请教:关于WRAP_CONTENT
- android 线程同步问题
- android开发环境搭建后,如何默认使得build path中包含android
- 新手学习android~求帮助~
- 执行程序报错:can't execute: Permission denied
- <Android导航菜单横向左右滑动并和下方的控件实现联动>---之数据加载
- 问一下android.media.AsyncPlayer这个类应该怎么用啊?
- 在android2.3模拟器上可以测试流媒体功能吗
- android.intent.action.DATE_CHANGED
程序启动的时候都会由信息保存到logcat里面
查它就可以了
* Return a list of the tasks that the user has recently launched, with
* the most recent being first and older ones after in order.
*
* @param maxNum The maximum number of entries to return in the list. The
* actual number returned may be smaller, depending on how many tasks the
* user has started and the maximum number the system can remember.
*
* @return Returns a list of RecentTaskInfo records describing each of
* the recent tasks.
*
* @throws SecurityException Throws SecurityException if the caller does
* not hold the {@link android.Manifest.permission#GET_TASKS} permission.
*/
public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
throws SecurityException {
try {
return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
flags);
} catch (RemoteException e) {
// System dead, we will be dead too soon!
return null;
}
}相信这个函数能达到你想要的结果
帮你找了个getRecentTask的例子,希望对你有帮助,如下:
public void getTaskList() {
ImageButton ivIcon;
ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
PackageManager pm = this.getPackageManager();
try {
List<RecentTaskInfo> list = am.getRecentTasks(64, 0);
llTaskBar.removeAllViews();
for (RecentTaskInfo ti : list) {
Intent intent = ti.baseIntent;
ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
if (resolveInfo != null) {
ivIcon = new ImageButton(this);
ivIcon.setImageDrawable(resolveInfo.loadIcon(pm));
ivIcon.setFocusable(true);
ivIcon.setClickable(true);
ivIcon.setEnabled(true);
ivIcon.setScaleType(ScaleType.CENTER);
ivIcon.setLayoutParams(new LinearLayout.LayoutParams(120, 120));
llTaskBar.addView(ivIcon);
}
}
} catch (SecurityException se) {
se.printStackTrace();
}
}
在ActivityManager 中 有一个publish的函数为:getRecentTasksThe information of this method are as below:/**
* Return a list of the tasks that the user has recently launched, with
……帮你找了个getRecentTask的例子,希望对你有帮助,如下:
public void getTaskList() {
ImageButton ivIcon;
ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
PackageManager pm = this.getPackageManager();
try {
List<RecentTaskInfo> list = am.getRecentTasks(64, 0);
llTaskBar.removeAllViews();
for (RecentTaskInfo ti : list) {
Intent intent = ti.baseIntent;
ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
if (resolveInfo != null) {
ivIcon = new ImageButton(this);
ivIcon.setImageDrawable(resolveInfo.loadIcon(pm));
ivIcon.setFocusable(true);
ivIcon.setClickable(true);
ivIcon.setEnabled(true);
ivIcon.setScaleType(ScaleType.CENTER);
ivIcon.setLayoutParams(new LinearLayout.LayoutParams(120, 120));
llTaskBar.addView(ivIcon);
}
}
} catch (SecurityException se) {
se.printStackTrace();
* Return a list of the tasks that the user has recently launched, with
……
frameworks/policies/base/phone/com/android/internal/policy/impl/RecentApplicationsDialog.java这个你可以借鉴一下