Log.v(“ThreeTips”, ”#12”)

Mert SIMSEK
2 min readFeb 9, 2017

--

1- Use PendingIntent right way

This is the method we usually use it to show notification.

PendingIntent.getActivity(context, requestCode, intent, flag);

But generally people share with us example like giving request code 0(zero). I am the one of copy/paste developer sometimes. But recently I faced with error using this line.

PendingIntent.getActivity(myContext, 0, myIntent, 0);

Whenever app receives notification, intent activity receives old data because of requestCode. Here is the documentation about that method.

Returns an existing or new PendingIntent matching the given
parameters.

So second parameter(requestCode) should be unique to intent. If you use same request code for every notification, activity will be receive old data. So your requestCode should be unique.

There is also another solution.Use PendingIntent.FLAG_UPDATE_CURRENT as flag. The doc says that;

If the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent.

2- Pass data to fragment by value

Passing object by reference : Let say you pass object from class1 to class2. If object is changed in class2. You will have changed object in class1. The reason is that they have same reference. So there is only one object instance.

Passing object by value : You will have copied instance in class2. And class1’s object will not be effected on change.

When you start an Activity and send data with intent/bundle. You will automatically pass your data by value. So you don’t have to worry about shared reference. But when you pass data to fragment with bundle, it will be passed by reference. So this means that If your object is changed in your fragment, your data will be changed in activity.

There are couple of workaround to pass by value to fragment. Easiest and fastest way is implement Parcelable and Clonable in your model class, then clone it before passing it.

public class DataModel implements Parcelable, Cloneable {...}
...
Bundle args = new Bundle();
args.putParcelable("data", (Product)data.clone());
myFragment.setArguments(args);

3- FCM Error : !@Too many alarms (500)

Recently we updated our app with FCM. But production app receives lots of error! After some research I found that it is because of firebase messaging module version. But it is fixed in 10.0.0 version. So you need to update your firebase version 10.0.0 or later. This will solve your problem.

If you like this series please recommend it to your friends. If you have any question please don’t hesitate to comment. :)

--

--

Mert SIMSEK
Mert SIMSEK

No responses yet