当前位置:   article > 正文

android 重新进入前台,Android 从后台进入前台

android movetasktofront

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/144852?site
推荐阅读