How do I use the onNewIntent method inside a fragment?

I am trying to use NFC hardware from my device. But the problem is when I register the action to get the intent:

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);


I am getting the result in Control instead of a Fragment. Is there a way to handle this result inside a fragment?

Thanks in advance!


source to share

1 answer


belongs to Activity, so you cannot use it in your fragment. What you can do is pass the data to your fragment when it arrives in onNewIntent

if you have a fragment reference.

Fragment fragment;  
protected void onNewIntent(Intent intent) {

    // Check if the fragment is an instance of the right fragment
    if (fragment instanceof MyNFCFragment) {
        MyNFCFragment my = (MyNFCFragment) fragment;
        // Pass intent or its data to the fragment method





All Articles