In my app i get notifications and when i click them it opens my app. I want them to check when i click them if the application is open and currently running(not just in taskmanager but in front of every app, as if the user is using it when the notification came) and if running then it wont reopen the app, but just removes the notification. And if the app isnt infront then the notification click will open it. How can i check if the app is in this state?
I tried things like this but this checks if the app is in the task manager: public boolean isProcessRunning(String process) {
ActivityManager activityManager = (ActivityManager) getApplicationContext()
.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> procInfos = activityManager
.getRunningAppProcesses();
for (int i = 0; i < procInfos.size(); i++) {
if (procInfos.get(i).processName
.equals("com.myapp")) {
return true;
}
}
return false;
}