Here is the situation I have got stuck. I want to know if there is any call back available if user manually kills the app (Like activity life cycle methods). Basically, I want to know weather the app is running or not. In running case, App may have 2 cases
- ForeGround
- Background
And third case can be app is not running at all. I have searched and I found if I use below code I can check weather app is in process.The code is below which I have used
ActivityManager activityManager = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningApps = activityManager.getRunningAppProcesses();
if (runningApps != null) {
for (ActivityManager.RunningAppProcessInfo processInfo : runningApps) {
if (processInfo.processName.equals(context.getPackageName())) {
return true;
}
}
}
This is returning true if the app is running (Foreground and background). And that is expected but the problem is when app is not background (app is manually killed by a user) not running at all, it is also returning true. What I believe this is happening because I am using forground service. Weather the app is killed but the service of the app is still running that's why the code mentioned returning true. I think running forground service causes Application Process alive. My question is If this is the case, how can I check if app is not running at all after killing by a user manually.