title: How I can increment counter in firebase database forever through android application when the user clicks on the button
body: <p>Here is my code.</p>
  
  <pre><code>package com.example.manali.likeex;
  
  import android.app.Activity;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.Toast;
  
  import com.google.firebase.database.DatabaseReference;
  import com.google.firebase.database.FirebaseDatabase;
  
  
  
  public class MainActivity2 extends Activity implements View.OnClickListener {
      Button senlike;
      private DatabaseReference mdatabase;
      private DatabaseReference user1;
  
       int c;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main2);
          Button sendlike = (Button) findViewById(R.id.b1);
          mdatabase= FirebaseDatabase.getInstance().getReference();
          user1=mdatabase.child("Teacher");
          sendlike.setOnClickListener(this);
  
      }
  </code></pre>
  
  <p>//when user clicks on button counter on firebase get increased
          public void onClick(View view)
          {</p>
  
  <pre><code>        if(user1!=null)
          {
              c++;
  
          }
  
  
  
  //sets value to user1 node
          user1.setValue(c);
  
      }
      public DatabaseReference getUser1()
      {
          return user1;
  
      }
  }
  </code></pre>
  
  <p>This code only increases counter when app is active. When we close the app, and restart it again. The counter starts again with 1. Hence I want to maintain this counter. </p>