或许你的Service在运行的时候需要知道当前运行的进程是不是你的app,
如果不是你的app在运行,那就给用户一个通知;否则不给。
private String getCurrentActivityName(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
// get the info from the currently running task
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
return componentInfo.getClassName();
}