title: Starting a function on a firestore update
body: <p>The question is as easy as the title sugests.</p>
  
  <p>To explain a little bit more, i'm a starter in android programming and I need my app to run a certain function everytime my firestore is updated.</p>
  
  <pre><code>protected void onStart(){
      super.onStart();
      mDocRef.addSnapshotListener(new EventListener&lt;DocumentSnapshot&gt;() {
          @Override
          public void onEvent(DocumentSnapshot documentSnapshot, FirebaseFirestoreException e) {
                  Map&lt;String,Object&gt; SMSFlag = new HashMap&lt;String, Object&gt;();
                  String quotenum = documentSnapshot.getString(NUM_KEY);
                  String quotemsg = documentSnapshot.getString(SMS_KEY);
  
                  state = documentSnapshot.getString(STATE_KEY);
                  if (state.equals("tosend")) {
                      try {
                          SmsManager smsManager = SmsManager.getDefault();
                          smsManager.sendTextMessage(quotenum, null, quotemsg, null, null);
                          Toast.makeText(MainActivity.this, "SMS Sent!", Toast.LENGTH_LONG).show();
                      } catch (Exception e1) {
                          Toast.makeText(MainActivity.this, "Error sending SMS: " + e, Toast.LENGTH_LONG).show();
                      }
                      SMSFlag.put(STATE_KEY, "sent");
                      mDocRef.set(SMSFlag);
                      state = documentSnapshot.getString(STATE_KEY);
                  }
          }
      });
  }
  </code></pre>
  
  <p>This is supposed to send a message. As you can see in the code I use a state key, this is because it was sending 3 sometimes 4 identical messages. After implementing the state it is sending only one (as its expected to) and sometimes two.</p>
  
  <p>I want to know if theres a android method that I can replace onStart() for, because I think the problem is the method itself.</p>
  
  <p>I hope I have explained myself well.
  Thank you in advance for anyone willing to help</p>