我想從我的廣播接收器中查找當前正在運行的其他活動。這是我從活動中使用它來查找其他運行activites但是當我嘗試在我的廣播接收器使用此代碼我得到以下行錯誤代碼:在Android中查找廣播接收器的運行活動
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
顯示在eclipse ACTIVITY_SERVICE誤差不能解析爲一個可變
PackageManager pm = this.getPackageManager();
,這表明在蝕該錯誤的方法getPackageManager()是未定義的類型ScreenReceiver(我的廣播接收機)
這裏是全碼:
public void getRunning(){
ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List l = am.getRunningAppProcesses();
Iterator i = l.iterator();
PackageManager pm = this.getPackageManager();
while(i.hasNext()) {
ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
try {
CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
Log.w("LABEL", c.toString());
runningApplications.add(c.toString());
}catch(Exception e) {
//Name Not Found Exception
}
}
}
要更加清楚這個問題:'this'指您正在操作的類實例。在這種情況下,是「BroadcastReceiver」的後代。所以'這個'與預期完全不同。 – yoshi 2012-07-17 20:00:35
runningApplications.add(c.toString()); <---什麼類型的runningApplications? – bofredo 2013-08-29 13:38:06