iappmaker
iappmaker

Reputation: 3005

Notification in android games

In am developing a game using LibGdx for Android devices. I wish to have the notification as it is there in CANDY CRUSH game. This is to give a alert or a remainder if the user is not playing the game for some days.

Could you please help how to do this ? Any Pointer / Example would be a great help.

Upvotes: 1

Views: 1038

Answers (2)

Gregory Fein
Gregory Fein

Reputation: 91

Aloupas is right about scheduling notifications. However, AlarmManager only works if the app has been run at least once to set the alarm and the phone hasn't been turned off. When the phone reboos/turns off, AlarmManager loses all of its pending stuff and they don't re-inflate when the system turns back on. I'd recommend the actual Android documents to check about Notifications in more broad sense, since there are a lot of types and a lot of solutions. Be warned, this stuff is dense, advanced, and finnicky as you move from API to API.

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

There's also another thought: push notifications. If you want to manually alert your users about something (new levels added, double XP weekend, etc.), you'd want to register your app for push notifications. The easiest platform for managing this would be Parse. Parse is a flexible and easy to use HTTP library, and it includes DB support on Android, so it's a two-for-one. It also supports push notifications out of the box.

https://www.parse.com/

Cheers.

Upvotes: 1

z3n105
z3n105

Reputation: 1995

You can use AlarmManager to schedule a notification.

Here is an example how you can schedule an alarm manager:

http://smartandroidians.blogspot.com/2010/04/alarmmanager-and-notification-in.html

and in alarmManager Receiver you can construct the notification and show it to the user for example in this stackoverflow question: How exactly to use Notification.Builder

Then in your Android Main Activity override onPause and onResume methods. OnResume cancel the alarmManager task and onPause start new alarmamanager.

Hope it helps

Upvotes: 1

Related Questions