Petar Mijović
Petar Mijović

Reputation: 347

Notification doesn't show up when app in background

I started developing android few days ago. My app needs to send a notification every morning and evening. It works if the app is in foreground if it is in background notification just doesn't show.

private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.ProgressPercentage == 2)
            {
                GenerateMorningNotification();
            }
            else if (e.ProgressPercentage == 3)
            {
                GenerateEveningNotification();
            }
        }

I use background worker, on progress changed event I use one of the method for generation of notification, for example:

private void GenerisiJutarnjuNotifikaciju()
{
    Notification.Builder builder = new Notification.Builder(this)
        .SetContentTitle("Dobro jutro")
        .SetStyle(new Notification.BigTextStyle().BigText(poruke.RandomPoruka()))
        .SetSmallIcon(Resource.Drawable.Icon);

    Notification notification = builder.Build();

    NotificationManager notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
    const int notificationId = 0;
    notificationManager.Notify(notificationId, notification);        
}

Any suggestions on what should I change? I am developing this app for my girlfriends birthday so I am kinda in a rush. If anyone can assist, I will be grateful. Thanks.

Upvotes: 1

Views: 115

Answers (1)

Lyla
Lyla

Reputation: 2777

I think an setting an Alarm using AlarmManager to trigger a BroadcastReceiver is generally what you use when you want something to happen at a certain time, even when the app isn't in the foreground.

The code here goes into pretty good detail about how that is done: Send notification once in a week

Upvotes: 1

Related Questions