在android中用什么方法可以获取最近打开过的程序?一直没有思路,请教高人指点!

解决方案 »

  1.   

    /dev/log/main在里面会保存logcat日志信息
    程序启动的时候都会由信息保存到logcat里面
    查它就可以了
      

  2.   

    在ActivityManager 中 有一个publish的函数为:getRecentTasksThe information of this method are as below: /**
         * 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;
            }
        }相信这个函数能达到你想要的结果
      

  3.   

    请问一下如果我想在gallery里放最近打开过的程序,怎么放呢?getRecentTasks(int maxNum, int flags)这个报错,说:非法修改参数getRecentTasks;只有最终是被允许的,这是什么意思呢?
      

  4.   


    帮你找了个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();  
        }  
    }  
      

  5.   

    记得加权限  <uses-permission android:name="android.permission.GET_TASKS"/>
      

  6.   

    <uses-permission android:name="android.permission.GET_TASKS"/>
      

  7.   


    在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();  
      

  8.   

    The information of this method are as below:/**
    * Return a list of the tasks that the user has recently launched, with
    ……
      

  9.   

    长摁Home ,弹出的Dialog会显示 从系统任务栈里检索的最近执行的8个应用 
    frameworks/policies/base/phone/com/android/internal/policy/impl/RecentApplicationsDialog.java这个你可以借鉴一下 
      

  10.   

    lltaskbar是个什么,能详细说下吗
      

  11.   

    能说下你贴的那段代码中lltaskbar是什么,怎么定义的吗,谢谢了