Skip to content

Firebase Messaging Service destroyed after message received #933

Description

@AmitMaraj

Step 1: Describe your environment

  • Android 7.0

  • Google Play Services version: 4.3.0

  • Firebase/Play Services SDK version: 20.0.0

Step 2: Describe the problem:
I have a class the extends FirebaseMessagingService. In this class i am registering a broadcast receiver as well.
I can receive the message in the onMessageReceived method and show a notification but the service is destroyed immediately after.

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = "MyFirebaseMsgService";
    private static DownloadCompleteReceiver downloadCompleteReceiver=new DownloadCompleteReceiver();

    @Override
    public void onCreate() {
        super.onCreate();

        showNotification();

        registerReceiver(downloadCompleteReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unregisterReceiver(downloadCompleteReceiver);
        Toast.makeText(this, "service destroyed", Toast.LENGTH_SHORT).show();
    }`

@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
  
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());

            sendNotification(remoteMessage.getData().toString());
        }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions