android获取正在运行的应用程序
2012-12-18 13:59:24 来源:WEB开发网核心提示://根据包名打开应用程序 Intent intent=new Intent(); intent =pm.getLaunchIntentForPackage(packageName); startActivity(intent); finish();//打开应用程序
//根据包名打开应用程序
Intent intent=new Intent();
intent =pm.getLaunchIntentForPackage(packageName);
startActivity(intent);
finish();//打开应用程序之后注销本应用程序
}
});
Intent intent=new Intent();
intent =pm.getLaunchIntentForPackage(packageName);
startActivity(intent);
finish();//打开应用程序之后注销本应用程序
}
});
//为listview的item添加长按事件
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
final HashMap<?, ?> long_map=(HashMap<?, ?>)parent.getItemAtPosition(position);
new AlertDialog.Builder(ManagerTasksActivity.this).setTitle("Are you sure close")
.setPositiveButton("sure", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
String packageName=(String)long_map.get("packagename");
//base packagename to kill appliction
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
final HashMap<?, ?> long_map=(HashMap<?, ?>)parent.getItemAtPosition(position);
new AlertDialog.Builder(ManagerTasksActivity.this).setTitle("Are you sure close")
.setPositiveButton("sure", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
String packageName=(String)long_map.get("packagename");
//base packagename to kill appliction
//根据包名杀死应用程序
am.killBackgroundProcesses(packageName);
//refash list
am.killBackgroundProcesses(packageName);
//refash list
//刷新listview
LoadList(ManagerTasksActivity.this);
}
}).setNegativeButton("cancle", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
return false;
}
});
}
}
LoadList(ManagerTasksActivity.this);
}
}).setNegativeButton("cancle", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
return false;
}
});
}
}
更多精彩
赞助商链接