'onNewIntent in Fragments in android
I am trying to develop a NFC application. I need to recognize the NFC TAG from the OnNewIntent
that in the Activity
class. Now I need to move and use fragments and not activity. Is their a way to replace the onNewIntent
in the fragment class?
Solution 1:[1]
According to here (https://stackoverflow.com/a/5320694/3736955), you cant catch NFC intent by BroadcastReceiver. The only way to handle it is by ForegroundDispatch and onNewIntent() function within activity. When NFC Tag is tapped, it looks for foreground activity to handle him.
Solution 2:[2]
Maybe the best possible approach will be calling the setIntent() function on the received intent while executing onNewIntent() of an Activity and retreiving it back via getActivity().getIntent() during a fragment lifecycle. Upd: Also you can use the pattern Observer to dispatch intent receiving events immediately to the registered fragments. Then you can obtain required data from getActivity().getIntent().
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |
Solution 2 |