title: android firebase database save data for current user
body: <p>I have an app that send sms templates with firebase user login.
  I want to save sms logs for each user on firbase database so I will be able to see what messages each user sent. I have no idea how to make it probably .. </p>
  
  <p>my code </p>
  
  <p>LoginActivity.java</p>
  
  <pre><code>public class LoginActivity  extends AppCompatActivity {
  private ProgressBar spinner;
  
  EditText EMAIL, PASSWORD;
  Button SIGNIN;
  private FirebaseAuth mAuth;
  private FirebaseAuth.AuthStateListener mAuthListener;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_login);
  
      mAuth = FirebaseAuth.getInstance();
  
      EMAIL = (EditText) findViewById(R.id.email);
      PASSWORD = (EditText) findViewById(R.id.password);
      SIGNIN = (Button) findViewById(R.id.login);
      spinner = (ProgressBar) findViewById(R.id.progressBar1);
      spinner.setVisibility(View.GONE);
  
  
      SIGNIN.setOnClickListener(new View.OnClickListener() {
  
  
              @Override
              public void onClick(View view) {
                  if ((TextUtils.isEmpty(EMAIL.getText().toString())) &amp;&amp; (TextUtils.isEmpty(PASSWORD.getText().toString()))) {
                      Toast.makeText(getApplicationContext(), "make sure that you enter full ogin info ", Toast.LENGTH_SHORT).show();
                  }else if (!isEmailValid(EMAIL.getText().toString())){
                      Toast.makeText(getApplicationContext(), "enter a valid mail", Toast.LENGTH_SHORT).show();
                  } else {
                      SignIn(EMAIL.getText().toString(), PASSWORD.getText().toString());
                  }
  
              }
          });
      SIGNIN.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              String pass = PASSWORD.getText().toString();
  
              if(TextUtils.isEmpty(pass)) {
                  PASSWORD.setError("kindly enter password ");
                  return;
              }
  
  
  
  
  
              if ((TextUtils.isEmpty(EMAIL.getText().toString())) &amp;&amp; (TextUtils.isEmpty(PASSWORD.getText().toString()))) {
                  Toast.makeText(getApplicationContext(), "wrong info", Toast.LENGTH_SHORT).show();
                  spinner.setVisibility(View.GONE);
  
              } else {
                  spinner.setVisibility(View.VISIBLE);
                  SignIn(EMAIL.getText().toString(), PASSWORD.getText().toString());
              }
  
          }
      });
  
  
      mAuthListener = new FirebaseAuth.AuthStateListener() {
          @Override
          public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
              FirebaseUser user = firebaseAuth.getCurrentUser();
              if (user != null) {
                  finish();
                  startActivity(new Intent(getApplicationContext(), MainActivity.class));
                  finish();
              }
          }
      };
      mAuth.addAuthStateListener(mAuthListener);
  
  
  }
  
  
  private void SignIn(String email, String password) {
      mAuth.signInWithEmailAndPassword(email, password)
              .addOnCompleteListener(new OnCompleteListener&lt;AuthResult&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                      if (task.isSuccessful()) {
                          finish();
                          Toast.makeText(getApplicationContext(), "login done",
                                  Toast.LENGTH_SHORT).show();
                          startActivity(new Intent(getApplicationContext(), MainActivity.class));
                          finish();
                      } else {
                          Toast.makeText(getApplicationContext(), "Error username",
                                  Toast.LENGTH_SHORT).show();
                          spinner.setVisibility(View.GONE);
  
                      }
  
                  }
              });
  }
  
  public static boolean isEmailValid(String email) {
      boolean isValid = false;
  
      String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
      CharSequence inputStr = email;
  
      Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
      Matcher matcher = pattern.matcher(inputStr);
      if (matcher.matches()) {
          isValid = true;
      }
      return isValid;
  }
  }
  </code></pre>
  
  <p>sms.java</p>
  
  <pre><code>public class Harsh extends AppCompatActivity {
  RadioButton lo, hi, mid;
  String sense;
  Button submit;
  
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.harsh_layout);
      lo = (RadioButton) findViewById(R.id.lo_btn);
      hi = (RadioButton) findViewById(R.id.hi_btn);
      mid = (RadioButton) findViewById(R.id.mid_btn);
      submit = (Button) findViewById(R.id.submitButton);
  
      SharedPreferences prefs = getSharedPreferences("MyPrefs", MODE_PRIVATE);
      final String num = prefs.getString("nameKey", "0");
  
      submit.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (lo.isChecked()) {
                  sendSMS( num, "  message one");
  
              } else if (hi.isChecked()) {
                 sendSMS( num, "  message 2");
              // for example save this message for current logged user
              } else if (mid.isChecked()) {
  
  
                sendSMS( num, "  message 3");
              }
              Toast.makeText(getApplicationContext(), "Command Sent", Toast.LENGTH_LONG).show(); // print the value of selected super star
          }
      });
  
  
  
  }
  public void sendSMS(String phoneNo, String msg) {
      try {
          SmsManager smsManager = SmsManager.getDefault();
          smsManager.sendTextMessage(phoneNo, null, msg, null, null);
          Toast.makeText(getApplicationContext(), "Command Sent",
                  Toast.LENGTH_LONG).show();
      } catch (Exception ex) {
          Toast.makeText(getApplicationContext(),ex.getMessage().toString(),
                  Toast.LENGTH_LONG).show();
          ex.printStackTrace();
      }
  }
  }
  </code></pre>