Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UserProfileActivity extends AppCompatActivity {
- // Creating button.
- Button logout;
- // Creating TextView.
- TextView userEmailShow, text, text2, text3, text4, text5, text6, text7;
- // Creating FirebaseAuth.
- FirebaseAuth firebaseAuth;
- TextView ShowDataTextView;
- String NameHolder, NumberHolder;
- // Creating FirebaseAuth.
- FirebaseUser firebaseUser;
- Firebase firebase;
- public static final String Firebase_Server_URL = "https://gakusei-
- go.firebaseio.com/";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_user_profile);
- // Assigning ID's to button and TextView.
- logout = (Button) findViewById(R.id.logout);
- userEmailShow = (TextView) findViewById(R.id.user_email);
- text = (TextView)findViewById(R.id.textView);
- text2 = (TextView)findViewById(R.id.textView2);
- text3 = (TextView)findViewById(R.id.textView3);
- text4 = (TextView)findViewById(R.id.textView4);
- text5 = (TextView)findViewById(R.id.textView5);
- text6 = (TextView)findViewById(R.id.textView6);
- text7 = (TextView)findViewById(R.id.textView7);
- // Adding FirebaseAuth instance to FirebaseAuth object.
- firebaseAuth = FirebaseAuth.getInstance();
- // On activity start check whether there is user previously logged in or not.
- if (firebaseAuth.getCurrentUser() == null) {
- // Finishing current Profile activity.
- finish();
- // If user already not log in then Redirect to LoginActivity .
- Intent intent = new Intent(UserProfileActivity.this, LoginActivity.class);
- startActivity(intent);
- // Showing toast message.
- Toast.makeText(UserProfileActivity.this, "Please log in to continue", Toast.LENGTH_LONG).show();
- }
- // Adding firebaseAuth current user info into firebaseUser object.
- firebaseUser = firebaseAuth.getCurrentUser();
- // Getting logged in user email from firebaseUser.getEmail() method and set into TextView.
- userEmailShow.setText("Welcome " + firebaseUser.getEmail());
- firebase.child("Student").addListenerForSingleValueEvent(new ValueEventListener() {
- @Override
- public void onDataChange(DataSnapshot MainSnapshot) {
- Student student = MainSnapshot.getValue(Student.class);
- // Adding name and phone number of student into string that is coming from server.
- String pname = student.getPname();
- String pnum = student.getPhonenumber();
- String sname = student.getStudentname();
- String email = student.getEmail();
- String dorm = student.getDorm();
- String password = student.getPassword();
- String clas = student.getStudentclass();
- text.setText(pname);
- text2.setText(pnum);
- text3.setText(sname);
- text4.setText(email);
- text5.setText(dorm);
- text6.setText(password);
- text7.setText(clas);
- }
- @Override
- public void onCancelled(FirebaseError firebaseError) {
- System.out.println("Data Access Failed" + firebaseError.getMessage());
- }
- });
Add Comment
Please, Sign In to add comment