Retrieving PackName from RecentTaskInfo

by Mark Hansen » Sat, 10 Apr 2010 01:42:38 GMT

Sponsored Links
 I'm  trying to the the application and icons for Recent Tasks, but I
can't seem to get the appInfo using the RecentTaskInfo.  The
getApplicationInfo call is what is failing due to the getPackageName()
returning null.

 ActivityManager manager =
 List<RecentTaskInfo> tasks = manager.getRecentTasks(50, 1);
        for (int counter = 0; counter < tasks.size(); counter++)
                RecentTaskInfo task =  tasks.get(counter);
                PackageManager pm = this.getPackageManager();

try {

                        ApplicationInfo appInfo  =
                       String applicationName =
                       Drawable icon = appInfo.loadIcon(pm);

I've also tried:

ApplicationInfo appInfo  =

In which getPackage() is returning null.. maybe I'm going about this
the wrong way and was hoping for some tips?


Retrieving PackName from RecentTaskInfo

by Mark Murphy » Sat, 10 Apr 2010 01:54:38 GMT


It may be there's a way to get things to work going down the path you're

Personally, I'd look at the source to RecentApplicationsDialog and see
how they do it. You can find this in Google Code Search by searching on:

package:android recentapplicationsdialog

The reloadButtons() method uses getRecentTasks(). They create an Intent
for each task, use resolveActivity() on PackageManager to get the
ResolveInfo on the activity, then use loadLabel()/loadIcon() to get the
display stuff.

Mark Murphy (a Commons Guy)  | 

Android App Developer Books: 


Sponsored Links

Other Threads

1. Surface Width/Height

I am sorry for my bad English.

I am beginner and have some problem. I use surfaceView and  in
surfaceChanged i get Width and Height  of SurfaceView. I get
width(320),height(403).Fragment code:

public void surfaceChanged(SurfaceHolder arg0, int format, int
width,int height) {
                mViewWidth = width;
                mViewHeight = height;
                System.out.println(mViewWidth+" "+mViewHeight);

 But resolution of my screen 320 x 240. How it is possible!?


2. Android emulator reports incorrect screen resolution

If I create an emulator on the command-line as:

./emulator.exe -avd my_avd -skin 480x360

The following calls all return a screen size of 480x320 and I have yet
to find a way to get the correct resolution returned without just hard-
coding it.

System.out.println("myView.getWH: "+myView.getWidth()
System.out.println("myView.getMeasuredWH: "+myView.getMeasuredWidth()
Rect r = new Rect();
System.out.println("hitRect: "+r.toString());

Incidentally, the hitbox is reporting a height of 320, but I am still
getting touch events with coordinates above 320 if I press on the
bottom of the emulator screen.

If I use a copy of the root view (myView.getRootView()), I am returned
the same 480x320 values. The root view here is an instance of$DecorView. The home
screen (this DecorView) and all of the built-in Android apps all
properly use the full 360 pixels specified as the height, but the only
way I can get my app to use all 360 is to hard-code its height. Hard-
coding for a particular resolution is obviously unacceptable since I
have to offer a one-build-for-all solution (and also because it's
extremely poor practice).

The properties of my_avd are Android 2.2, custom resolution 480x360
(as opposed to a built-in), Abstracted LCD density 160, Max VM
application heap size 24.


3. Possible to use OpenGL in both C++ and Java?

4. which is the best for android rtmp or rtsp?

5. Admob Confusion

6. Min SDK version vs target SDK vs actual android version app runs on

7. Why WebView can't click on the link