0

I create Firebase service and I want save data to room when I get Notification. I use MVP and I do not understand how can I use MVP in android.app.Service

public class MyFirebaseMessagingService extends FirebaseMessagingService {


    @Inject
    EventPresenter presenter;

    public NfpFirebaseMessagingService() {
        presenter = UserApplication.me().getAppComponent().getEventPresenter();
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map<String, String> data = remoteMessage.getData();
        presenter.saveEvent(data);
        sendNotification(remoteMessage.getData());
    }

but my presenter has view and FirebaseMessagingService - is not view. How can I realize MVP in this case?

nhoxbypass
  • 9,695
  • 11
  • 48
  • 71
ip696
  • 6,574
  • 12
  • 65
  • 128

1 Answers1

0

You can tread Service as your View. It can implement an interface which do not need to be called View, but you can rename it to Service.

You can just simply prepare interface:

interface ServiceI {
  void emitEvent();
}

than your service needs to implement this interface

public class MyFirebaseMessagingService extends FirebaseMessagingService implements ServiceI {
...
}

and you can pass this object to the presenter.

Patryk Jabłoński
  • 697
  • 10
  • 29