Android - 安装及卸载应用,启动应用程序,分享,详细信息,设备进程信息获取,获取进程占用RAM

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值