Domanda

I have an Activity with two fragments. In one fragment, when the button 'Notify' is clicked, a notification object has to be created. Can someone give me an example on how to create a notification in a fragment?

È stato utile?

Soluzione

It works the same way as in an activity, so you can use an example from the Android documentation.

The only difference is that you need to use getActivity() to get the system service:

NotificationManager mNotificationManager =
    (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top