【Android】把APP从后台调到前台

后台调到前台

Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new ComponentName(getApplicationContext().getPackageName(), MainActivity.class.getName()));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);

打开APP

private void openAPP(String appPackageName){
    try{
        //如果有,直接打开
        Intent intent = this.getPackageManager().getLaunchIntentForPackage(appPackageName);
        startActivity(intent);
    }catch(Exception e){
        Toast.makeText(this, "没有安装", Toast.LENGTH_LONG).show();
    }
}

推荐阅读更多精彩内容