title: How to connect firebase database to an android studio project where i am using sharedpreference
body: <p>So i am using sharedpreference in a voter app and i want to reset counts so that users can vote again next time</p>
  <p>So there are 10 counters with 10 textview
  I want at perticular time that counts at zero meaning i want to reset that counts but at perticular time.
  So how can i connect this to firebase so that everytime users will vote vote also increase in firebase database and at perticular time like 12 am i will manually update that value on zero so users can bote again for the same thing.</p>
  <p>Main activity</p>
  <pre><code>&lt;public class MainActivity extends AppCompatActivity {  
       TextView tv10;  
       Button btn10;  
       int  counter10 = 0;  
       u/Override  
       protected void onCreate(Bundle savedInstanceState) {  
       super.onCreate ( savedInstanceState );  
      setContentView ( R.layout.*activity\_main* );  
  
  
      btn10 = findViewById ( R.id.*btn10* );  
       tv10 =findViewById ( R.id.*tv10* );  
       counter10= test10.*loadtotalfrompreftest10*  ( this );  
       tv10.setText ( Integer.*toString* ( counter10 ) );  
  
  
      btn10.setOnClickListener ( new View.OnClickListener ( ) {  
       u/Override  
       public void onClick(View v) {  
       counter10++;  
       test10.*saveTotalInPreftest10* ( getApplicationContext (),counter10 );  
       tv10.setText ( Integer.*toString* ( counter10 ) );  
       Toast.*makeText* ( getApplicationContext (),&quot;you clicked button 
      10&quot;,Toast.*LENGTH\_SHORT* ).show ();  
  
  
      }  
      } );  
  
  
         }  
      }
  
  </code></pre>
  <p>Class file</p>
  <pre><code> private static final String *MY\_PREFERENCE\_NAME* = &quot;package com.example.voting&quot;;  
       private static final String *PREF\_TOTAL\_KEY10* = &quot;pref\_total\_key10&quot;;  
  
  
      public  static void saveTotalInPreftest10(Context context, int test10total){  
  
  
      SharedPreferences pref = context.getSharedPreferences ( 
         *MY\_PREFERENCE\_NAME*,Context.*MODE\_PRIVATE* );  
       SharedPreferences.Editor editor = pref.edit ();  
       editor.putInt ( *PREF\_TOTAL\_KEY10*,test10total );  
       editor.apply ();  
  
  
         }  
       public static int loadtotalfrompreftest10 (Context context){  
       SharedPreferences pref = context.getSharedPreferences (  *MY\_PREFERENCE\_NAME*,Context.*MODE\_PRIVATE* );  
       return pref.getInt ( *PREF\_TOTAL\_KEY10*,0 );  
      }  
  
  
      }    
  </code></pre>
  <p>Xml file</p>
  <pre><code>&lt;?*xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;*?&gt;*  
      &lt;androidx.constraintlayout.widget.ConstraintLayout 
           xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;  
           xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;  
           xmlns:tools=&quot;http://schemas.android.com/tools&quot;  
           android:layout\_width=&quot;match\_parent&quot;  
           android:layout\_height=&quot;match\_parent&quot;  
           tools:context=&quot;.MainActivity&quot;&gt;  
  
  
         &lt;Button  
       android:id=&quot;@+id/btn10&quot;  
       android:layout\_width=&quot;178dp&quot;  
       android:layout\_height=&quot;113dp&quot;  
       android:text=&quot;Button&quot;  
       app:layout\_constraintBottom\_toBottomOf=&quot;parent&quot;  
       app:layout\_constraintEnd\_toEndOf=&quot;parent&quot;  
       app:layout\_constraintStart\_toStartOf=&quot;parent&quot;  
       app:layout\_constraintTop\_toTopOf=&quot;parent&quot; /&gt;      
  
  
         &lt;TextView  
       android:id=&quot;@+id/tv10&quot;  
       android:layout\_width=&quot;119dp&quot;  
       android:layout\_height=&quot;88dp&quot;  
       android:text=&quot;0&quot;  
       app:layout\_constraintBottom\_toTopOf=&quot;@+id/btn10&quot;  
       app:layout\_constraintEnd\_toEndOf=&quot;parent&quot;  
       app:layout\_constraintStart\_toStartOf=&quot;parent&quot;  
       app:layout\_constraintTop\_toTopOf=&quot;parent&quot; /&gt;  
      &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;         
  
  </code></pre>