My app receives the GCM messages instantly if the phone is connected to the network. But the devices does not receive the messages when user turns off the network and reconn
You delay_while_idle should be true, from GCM APi docs
If the device is connected but idle, the message will still be delivered right away unless the delay_while_idle flag is set to true. Otherwise, it will be stored in the GCM servers until the device is awake. And that's where the collapse_key flag plays a role: if there is already a message with the same collapse key (and registration ID) stored and waiting for delivery, the old message will be discarded and the new message will take its place (that is, the old message will be collapsed by the new one).
You are using a collapsable key so only one will be keep on the GCM servers while the device is idle.
In the code:
Message message = new Message.Builder()
.delayWhileIdle(true)
//..