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

Mert SIMSEK
2 min readJan 10, 2017

--

1- OnKeyListener is called twice

Recently, I am working on a chat module on my app. We have a create conversation activity and user can search and add user to list. But I faced with a weird problem here. I wanted to achieve that If user click delete button from soft keyboard, last added user should be deleted just like Inbox app. It was easy to do. Set key listener to search text and listen for KeyEvent.KEYCODE_DEL. But when i click delete button from keyboard, it removes last 2 item from added user list?!. Because Key Listener called twice. One for key down, one for key up. That is why you should check and put condition there like,

2- Android Studio error message limit

Java compiler shows only first 100 error messages in console. If you use dagger 2 and databinding together in android, you can get more than 100 error messages(Because of databinding generated class errors).This code snippet helps you to show all error messages to see correct exception. I think 500 is a fear number.

gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "500"
}
}

3- FCM onMessageReceived() is not called

As we all know that how cloud messaging works basically. We implement Firebase Message receiver and if any notification arrives to device we expect that onMessageReceived method is called. So we can do anything with that notification payload. In FCM that is a little different.

There are two types of notification. Notification Type and Data Type.

In Notification Type notifications, If you device is foreground your onMessageReceived method works as intented. But if your app is background or killed, onMessageReceived is not called. App receives the notification payload in the notification tray, and only handles the data payload when the user taps on the notification. Actually It seems like I am complaining about this situation but this is intentional by firebase.

If you want onMessageReceived method gets called any time notification arrives, then you should use Data Message type notification.

Here is a json that includes both notification and data types.

{
"to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}

As I said before it is not a problem in firebase notification system. It is working as intented, but this may not meet your needs.

If you like this blogpost, you can use recommend button bottom left:)

--

--

Mert SIMSEK
Mert SIMSEK

Responses (1)