以下是我省去首尾后代码的主要部分。我想实现的功能就是显示后台运行程序的名称。
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); public static HashSet<String> getRunningApps(Context context) { final HashSet<String> hashSet = new HashSet<String>(); final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); final PackageManager packageManager = context.getPackageManager(); List<RunningTaskInfo> runningTasks = activityManager.getRunningTasks(Integer.MAX_VALUE); for (RunningTaskInfo runningTaskInfo : runningTasks) { String packageName = runningTaskInfo.baseActivity.getPackageName(); try { String appName = packageManager.getApplicationInfo(packageName, 0).loadLabel(packageManager).toString(); hashSet.add(appName); } catch (NameNotFoundException exception) { // handle Exception } } return; }
}
然后在eclipse上显示“ public static HashSet<String> getRunningApps(Context context) { ” 这一行有错,错误为:
Multiple markers at this line - Syntax error on token "(", ; expected - Illegal modifier for parameter getRunningApps; only final is permitted - Syntax error on token ")", ; expected
谁能教教我怎么改?尤其是说“不用()应该用;”的怎么改啊?
扬帆大鱼
白板的微信