I'm trying to open a fragment
initialized in an Activity through Firebase Cloud Messaging.
The fragment call works when the application is open, but once I close the application the push notification only opens the Activity and not the fragment.
MyActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//All my initial code
Intent i = getIntent();
Bundle extras = i.getExtras();
if(extras != null) {
String push = extras.getString("push");
if (push != null) {
Integer id = Integer.parseInt(extras.getString("id"));
goToDetalleDenuncia(id);
}
}else
goToMenu();
}
What I can do to debug (or resolve) this issue? I can't use Logcat (at least using eclipse) because the application is closed at this point
Finally, I found a solution for my issue.
Well, first one, the FCM notification can't call a fragment directly. You must use the
click_action
parameter in your intent.First one Manifest.xml
Here, you must add in the
intent-filter
section anaction android:name
and specify a name. In my case I used the same package name follow of ".MAIN" (Symbolizing the MainActivity but you could use some other name).MyFirebaseMessagingService.java
In the declaration of my
Intent
I addedExtra
to send some parameters to the activity.MyActivity.java
Well, when the application is running, you can get the parameter with the first
if
statement and get them with:extras.getString("push")
BUT, if your application is running in background (or it's closed) you must get the paramters with:
Why "tag"? In my
MyFirebaseMessagingService
I get the "tag" and I put it into an "id" key inExtra
for my Intent.And my json from my server like:
And in this way, now I can open an specific
Fragment
usingFCM
when the application is running, when is in background and when it's closed.Hope this helps you.