0

I have a Player fragment where I am hiding a View in inactive state of fragment. I am using setUserInteractionListener() in fragment to do this but the problem is it's applying on other fragments as well which I don't want. Can anyone help me with this? Is there any another option to interact with inactive fragment after 5 seconds?

I want to show below toast message only in player fragment but because of onUserInteraction() it shows on every fragment.

((MyActivity) getActivity()).setUserInteractionListener(this);
    runnable = () -> {
     Toast.makeText(getActivity(), "User is  not interact from last 5 seconds", Toast.LENGTH_SHORT).show();
    };
    handler.postDelayed(runnable, 7000);
Kat
  • 1
  • 2

1 Answers1

0

The reason why you are getting that view in other fragments is because ((MyActivity) getActivity()).setUserInteractionListener(this); is listening to the activity the fragment is attached to, and not the fragment itself. A possible workaround for this could be to create a interface that the fragment implements. An example of this workaround is explained in this question

Mateo Hervas
  • 545
  • 1
  • 5
  • 20