I searched around but couldn't find an answer.
My app is based on fragments, and MainActivity
is the entry point. When the user clicks on a notification, I trigger the desired behaviour with a PendingIntent
that contains specific flags as to what fragment needs to be invoked.
My problem occurs when the fragment I need is already being displayed. When the MainActivity
is entered through the PendingIntent
, the fragmentManager.getBackStackEntryCount()
will return zero. I guess that this happens because the activity is a different instance than what I already had running. Then the same fragment is invoked again and this messes up my UI (and potentially crash because the Otto
bus had already been registered).
My question is: what is the best way to detect the state of the running app (i.e. which fragment is being displayed) when the activity is triggered from a notification? Thanks.