0

I'm new in android app coding, and I am facing a question.

MainActivity has a navigationView, which links with different classes
A class I called "Station", so it will call like this

myFragment = new Station();

Station class extends Fragment, I used it to create fragments named

  • Station_General_Fragment
  • Station_ER_Fragment
  • Station_WR_Fragment

MainActivity also has a MediaPlayer (I call it mp1), and I'm trying to do OnCompletionListener for mp1, each fragment does different things in OnCompletionListener

The trouble I am facing is
Different OnCompletionListener in different classes mess up each other

What I am trying to do is

  • Get what fragment the activity is viewing
  • Compare with the fragment that OnCompletionListener located at
  • If equals, then do the code inside OnCompletionListener of that fragment

Anyone can help me? I can explain more if anyone wanna help me but don't know what I am talking about. Thank You

i998979
  • 13
  • 5
  • Please provide a [mcve] to illustrate the problem. To keep it minimal, I suggest that you start a new Android Studio project and add only the code you need to reproduce your issue. – Code-Apprentice May 03 '18 at 16:51
  • Possible duplicate of [get currently displayed fragment](https://stackoverflow.com/questions/9294603/get-currently-displayed-fragment) – Bö macht Blau May 03 '18 at 17:21

0 Answers0