Buggy code:
public class GcmIntentService extends IntentService { public static final int NOTIFICATION_ID = 1 ; private NotificationManager mNotificationManager ; public GcmIntentService ( ) { } private DataSource datasource ; private KeyHandler keyHandler ; private AdressBook adressBook ; private ServerConnection serverConnection ; @ Override protected void onHandleIntent ( Intent intent ) { } private void sendNotification ( Bundle data ) { keyHandler = KeyHandler . getInstance ( ) ; datasource = DataSource . getInstance ( this ) ; adressBook = AdressBook . getInstance ( ) ; serverConnection = ServerConnection . getInstance ( ) ; mNotificationManager = ( ( NotificationManager ) ( this . getSystemService ( NOTIFICATION_SERVICE ) ) ) ; PendingIntent contentIntent = PendingIntent . getActivity ( this , 0 , new Intent ( this , MainActivity . class ) , 0 ) ; Map < String , String > messageMap = new HashMap < > ( ) ; String content = data . getString ( getString ( message_content ) ) ; String sender = data . getString ( getString ( message_sender ) ) ; String keyBlock = data . getString ( getString ( message_keyblock ) ) ; messageMap . put ( getString ( message_sender ) , sender ) ; messageMap . put ( getString ( message_content ) , content ) ; messageMap . put ( getString ( message_keyblock ) , keyBlock ) ; Log . i ( getString ( debug_tag ) , messageMap . toString ( ) ) ; String encryptedMessage = keyHandler . decryptMessage ( messageMap . get ( getString ( message_content ) ) , keyHandler . getKeyBlockfromEncoded ( messageMap . get ( getString ( message_keyblock ) ) ) ) ; Log . i ( getString ( debug_tag ) , encryptedMessage ) ; messageMap . put ( getString ( message_content ) , encryptedMessage ) ; long [ ] pattern = new long [ ] { 0 , 500 , 0 } ; NotificationCompat . Builder mBuilder = new NotificationCompat . Builder ( this ) . setSmallIcon ( ic_launcher ) . setContentTitle ( getString ( notification_title ) ) . setStyle ( new NotificationCompat . BigTextStyle ( ) . bigText ( ( ( ( messageMap . get ( getString ( message_sender ) ) ) + ":<seq2seq4repair_space>" ) + ( messageMap . get ( getString ( message_content ) ) ) ) ) ) . setContentText ( ( ( ( messageMap . get ( getString ( message_sender ) ) ) + ":<seq2seq4repair_space>" ) + ( messageMap . get ( getString ( message_content ) ) ) ) ) . setVisibility ( VISIBILITY_PRIVATE ) . setVibrate ( pattern ) . setLights ( MAGENTA , 500 , 500 ) ; mBuilder . setContentIntent ( contentIntent ) ; mNotificationManager . notify ( GcmIntentService . NOTIFICATION_ID , mBuilder . build ( ) ) ; if ( ! ( adressBook . isContact ( messageMap . get ( getString ( message_sender ) ) ) ) ) { adressBook . storeNewContact ( messageMap . get ( getString ( message_sender ) ) , serverConnection . requestPubKey ( messageMap . get ( getString ( message_sender ) ) ) ) ; } int senderId = adressBook . getContactId ( messageMap . get ( getString ( message_sender ) ) ) ; <START_BUG> int receiverId = adressBook . getContactId ( adressBook . getUserName ( ) ) ; <END_BUG> Message messageObject = new Message ( senderId , receiverId , messageMap . get ( getString ( message_content ) ) ) ; datasource . storeMessageInDb ( messageObject ) ; adressBook . setUnreadMessage ( messageMap . get ( getString ( message_sender ) ) ) ; Intent intentToMain = new Intent ( getString ( intent_refresh_main_view ) ) ; LocalBroadcastManager . getInstance ( this ) . sendBroadcast ( intentToMain ) ; Intent intentToMessageView = new Intent ( getString ( intent_refresh_message_view ) ) ; intentToMessageView . putExtra ( "message" , messageMap . get ( getString ( message_sender ) ) ) ; LocalBroadcastManager . getInstance ( this ) . sendBroadcast ( intentToMessageView ) ; } }

Fix:
int receiverId = adressBook . getUserId ( ) ;