Pergunta

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?

Foi útil?

Solução

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);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top