re-open background application via notification item

前端 未结 6 1742
生来不讨喜
生来不讨喜 2020-12-10 07:14

I got an app with tabs and a notification bar entry, when I send it to background (click on home button) and try to re-open the application via click on the notification ba

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 08:16

    public static boolean isApplicationRunningBackground(final Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List tasks = am.getRunningTasks(am.getRunningAppProcesses().size());
        for (RunningTaskInfo runningTaskInfo : tasks) {
            if (runningTaskInfo.topActivity.getPackageName().equals(context.getPackageName())) {
                MyLog.i("UTIL", "packageName:" + runningTaskInfo.topActivity.getPackageName());
                MyLog.i("UTIL", "className" + runningTaskInfo.topActivity.getClassName());
                return true;
            }
        }
        return false;
    }
    
    Intent notificationIntent;
            if (Util.isApplicationRunningBackground(context)) {
                notificationIntent = new Intent(context, MainView.class);
            } else {
                notificationIntent = new Intent(context, Splash.class);
            }
    

提交回复
热议问题