Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
public class ParentNotificationCreator extends CoreNotificationCreator {
private Map<String, Class<? extends CoreNotification>> messageTypeForNotification;
public ParentNotificationCreator(Context context, Map<String, Class<? extends CoreNotification>> messageTypeForNotification) {
super(context);
this.messageTypeForNotification = messageTypeForNotification;
}
@Nullable
@Override
protected CoreNotification factoryMethod(String messageType, RemoteMessage remoteMessage) {
Class<? extends CoreNotification> notificationClass = messageTypeForNotification.get(messageType);
if (notificationClass != null) {
return notificationClass.getConstructor(RemoteMessage.class).newInstance(remoteMessage);
}
return null;
}
}
Map<String, Class> messageTypeForNotification = new HashMap<>();
messageTypeForNotification.put(PickUpNotification.TYPE, PickUpNotification.class);
messageTypeForNotification.put(GradeNotification.TYPE, GradeNotification.class);
new ParentNotificationCreator(context, messageTypeForNotification);
«Фабричный метод» в разработке под Android. Лучший способ обработки пушей