title: FCM notification message values not inserted into the mobile's sqlite database
body: <p><strong>I send the FCM notification message to the app and store the message body and title into SQLite database, it works fine when I test it when device is connected to computer but when I detached the device from system and test it, then I got Notification message only but it not saved into the SQLite. I am not able what the exact problem because when I debug the code it works fine and save data properly into the SQLite and show appropriate result to me.</strong></p>
  
  <pre><code>@Override
  public void onCreate(SQLiteDatabase db) {
  
  db.execSQL(CREATE_QUERY);
  Log.d("LOGCAT", "Table created successfully");
  }
  
  // this method is used for insert the MESSAGE into the SQLite 
  
  database......
      public void addInformation(String msg_title, String msg_body, SQLiteDatabase db){
          db = this.getWritableDatabase();
      try{
          ContentValues contentValues = new ContentValues();
          //contentValues.put(MESSAGE_ID,msg_ID);
          contentValues.put(MESSAGE_TITLE,msg_title);
          contentValues.put(MESSAGE_BODY,msg_body);
  
          db.insert(TABLE_NAME, null, contentValues);
          Log.d("SANTRIKA", "One row is inserted...");
  
          //To check row inserted correctly or not in database.....
          Long rowInserted = db.insert(TABLE_NAME,null,contentValues);
          if(rowInserted != -1){
              Toast.makeText(context,"One row is `inserted...",Toast.LENGTH_SHORT).show();`
          }
          else {
              Toast.makeText(context,"Something wrong...",Toast.LENGTH_SHORT).show();
          }
  
          db.close();
      }catch (Exception e){
          e.printStackTrace();
  
      }
  }
  
  // this method is used for getting all the MESSAGE from the SQLite `database into listview layout......`
  public Cursor getInformation(SQLiteDatabase db){
      Cursor cursor;
      db = this.getReadableDatabase();
  
      String[] projections = {MESSAGE_ID,MESSAGE_TITLE,MESSAGE_BODY};
      cursor = db.query(TABLE_NAME,projections,null,null,null,null,null);
      return cursor;
  }
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
      onCreate(db);
  }
  </code></pre>
  
  <p>//DBHelper classs.........</p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
  private static final String TAG = "MyFirebaseMsgService";
  SQLiteDatabase db;
  DatabaseHandler databaseHandler;
  
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
      //Displaying data on log... it is optional....
  
      Log.d(TAG,"From ="+remoteMessage.getFrom());
      String from = remoteMessage.getFrom();
      Log.d(TAG, "Notification Message Body = " + remoteMessage.getNotification().getBody());
  
      String title = remoteMessage.getNotification().getTitle();
      String message = remoteMessage.getNotification().getBody();
  
      //store message data into the SQLite database.....
      insertMessage(title, message);
  
      //Calling method to get notification...
      sendNotification(remoteMessage.getNotification().getBody());
  }
  
  //This method is only generating push notification...
  private void sendNotification(String messageBody){
      String _messageBody = messageBody;
      Intent intent = new Intent(this,Message_Inbox_Activity.class);
      //intent.putExtra("messageBody", _messageBody);
  
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //  startActivity(intent);
  
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
  
      Uri defalutSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  
      NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
              .setSmallIcon(R.mipmap.ic_launcher)
              .setContentTitle("SANTRIKA Push Notification")
              .setContentText(messageBody)
              .setAutoCancel(true)
              .setSound(defalutSoundUri)
              .setContentIntent(pendingIntent);
  
      NotificationManager notificationManager =  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  
      notificationManager.notify(0, notificationBuilder.build());
  }
  
  public void insertMessage(String title, String body){
  
      String t= title;
      String b = body;
      Log.d("title", t);
      Log.d("body",b);
      String temp = "rajesh";
      databaseHandler = new DatabaseHandler(this);
  
      databaseHandler.addInformation(title, body, db);
  
  }
  </code></pre>