In my application i want to show a message using BroadcastReceiver, but i want it to display the toast message only when the application is not opened and currently running on the screen (it may be running in the background). But i am not finding the exact code to implement the condition accordingly.
I have tried the code,
ActivityManager manager =
(ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
but it stop the message when running another application also.
Please help how i can make my code aware about whether the application currently opened or not? Thanks.