Search…
Notifications
Notification is a message that will be displayed to the user outside of the application’s usual UI.
When you execute a command telling the system to issue a notification, it will appear as an icon in the notification area, and to see the details, the user opens the notification space.
The notification space is this area where the details are shown (also called the notification drawer) are areas controlled by the system and the user can see at any time.

Creation of a Notification

  • To specify actions and information that will be displayed to the user, use a Notification.Builder object.
  • To create a push notification, use Notification.Builder.build(), which is an example of the type of notification provided as previously defined specifications.
  • To notify a notification, simply pass the Notification object using NotificationManager.getInstance().Notify();

Content Needed to Create a Notification

The object on smartphones should contain the following:
  • A title, defined by title();
  • Detail text, defined by text();

A Simple Example

HelloTCNotification
1
import totalcross.notification.Notification;
2
import totalcross.notification.NotificationManager;
3
import totalcross.sys.Settings;
4
import totalcross.ui.Button;
5
import totalcross.ui.Edit;
6
import totalcross.ui.MainWindow;
7
8
public class HelloWorld extends MainWindow {
9
private Button btnHello;
10
11
public HelloWorld(){
12
super("", NO_BORDER);
13
Settings.uiAdjustmentsBasedOnFontHeight = true;
14
setUIStyle(Settings.Material);
15
}
16
17
public void initUI() {
18
Edit title = new Edit("Title");
19
title.caption = "Title";
20
add(title, LEFT+150, TOP+100, FILL-150, PREFERRED);
21
22
Edit text = new Edit("Text");
23
text.caption = "Text";
24
add(text, LEFT+150, AFTER+50, FILL-150, PREFERRED);
25
26
btnHello = new Button("Notify!");
27
btnHello.addPressListener(
28
(e) -> {
29
Notification.Builder builder = new Notification.Builder();
30
Notification notification = builder
31
.title(title.getText())
32
.text(text.getText())
33
.build();
34
NotificationManager.getInstance().notify(notification);
35
});
36
add(btnHello, CENTER, AFTER+150, PARENTSIZE+38, PARENTSIZE+8);
37
}
38
}
Copied!

References

Last modified 2yr ago