赞
踩
public void moveTaskToFront(int taskId, int flags) {
try {
ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags);
} catch (RemoteException e) {
// System dead, we will be dead too soon!
}
//获取ActivityManager
ActivityManager mAm = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
//获得当前运行的task
List
for (ActivityManager.RunningTaskInfo rti : taskList) {
//找到当前应用的task,并启动task的栈顶activity,达到程序切换到前台
if(rti.topActivity.getPackageName().equals(context.getPackageName())) {
mAm.moveTaskToFront(rti.id,0);
return;
}
}
//若没有找到运行的task,用户结束了task或被系统释放,则重新启动mainactivity
Intent resultIntent = new Intent(context, MainActivity.class);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(resultIntent);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。