userAppInfos.remove(deleteAppInfo);
}
方法二:使用迭代器进行遍历,可在遍历中删除
Iterator iterator = userAppInfos.iterator();
while(iterator.hasNext()){
AppInfo appinfo = iterator.next();
if (appinfo.getPackName().equals(packname)) {
iterator.remove();
}
}
方法三:使用普通for循环倒叙,可在遍历中删除。注意:如不采用倒叙,会遍历不全
for (int i = userAppInfos.size() - 1; i >= 0; i–) {
AppInfo appinfo = userAppInfos.get(i);
if (appinfo.getPackName().equals(packname)) {
userAppInfos.remove(i);
break;
}
}
4.启动一个应用程序
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(clickedAppInfo.getPackName());
if(intent!=null){
startActivity(intent);
}else{
Toast.makeText(this, “对不起,该应用无法被开启”, 0).show();
}
5.分享
Intent intent = new Intent();
intent.setAction(“android.intent.action.SEND”);
intent.addCategory(“android.intent.category.DEFAULT”);
intent.setType(“text/plain”);
intent.putExtra(Intent.EXTRA_TEXT, “推荐你使用一款软件:”+clickedAppInfo.getAppName()+“,真的很好用哦”);
startActivity(intent);
6.详细信息
Intent intent = new Intent(“android.settings.APPLICATION_DETAILS_SETTINGS”);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(“package:”+clickedAppInfo.getPackName()));
startActivity(intent);
7.设备进程信息获取
获取设备运行进程
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List runningAppProcessInfos = am.getRunningAppProcesses();
获取设备RAM
MemoryInfo outInfo = new ActivityManager.MemoryInfo();
am.getMemoryInfo(outInfo);
outInfo.availMem;//设备可用RAM
outInfo.totalMem;//设备总RAM
8.获取进程占用RAM
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo[] processMemoryInfo = am.getProcessMemoryInfo(new int[]{info.pid});
long memSize = processMemoryInfo[0].getTotalPrivateDirty()*1024;
9.ListView中Item中有CheckBox、Button等的焦点处理
ListView的item布局中有CheckBox、Button等会获取焦点的控件会抢走焦点,造成ListView的item点击事件相应不了
解决方法:控件设置
android:clickable=“false”
android:focusable=“false”
或者
android:focusable=“false”
//descendant 后裔; 后代; (由过去类似物发展来的) 派生物; 弟子;
android:descendantFocusability=“blocksDescendants”
10.ListView中getItemAtPosition()的使用
ListView的getItemAtPosition()方法的返回值即为adapter中getItem()方法返回的对象
11.清理进程
1.添加权限
2.具体实现
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
am.killBackgroundProcesses(String pkgName);