Notification doesn't appear in foreground service
<p>I'm using the following code:</p>

<pre><code>private void startForeground(boolean isActive) {
        Intent notificationIntent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Notification notification = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(getString(isActive ? R.string.title_agent_active : R.string.title_agent_inactive))
                .setContentIntent(pendingIntent)
                .build();

        startForeground(1, notification);
    }
</code></pre>

<p>and </p>

<pre><code> @Override
    protected void onHandleIntent(Intent intent) {
        startForeground(true);
        ...
</code></pre>

<p>With this code notification does not appear.</p>

<p>But if I replace startForeground(...) with NotificationManager.notify(...) — it shows the notification, so, I think, that at least notification building code is ok.</p>

<p>Where could be the problem? </p>