android


The Activity restart after saving data in Firebase


Im trying to save user information in Firebase Database but a strange behavior happens that make the Save button to restart the same activity not the Intent that i made for the next activity .
public void userData () {
user.setFName(Fname.getText().toString());
user.setLName(Lname.getText().toString());
user.setEmail(Email.getText().toString());
user.setAddress(userAddress.getText().toString());
user.setPassword(UserInfo.getString("Password", ""));
user.setID(CicID.getText().toString());
user.setUsername(Usnm.getText().toString());
if (bAdmn.isChecked()) user.setMajor("Business Administrator");
if (BTech.isChecked()) user.setMajor("Business Tech");
if (masscom.isChecked()) user.setMajor("Mass Com");
if (Eng.isChecked()) user.setMajor("Engineering");
final String us = user.getUsername();
Log.i("Username", us);
MyDatabase1.child("USERS").child(us).setValue(user);
Intent i = new Intent(getApplicationContext() , chooseCoursesActivity.class);
startActivity(i);
}
that is the method for save button , Note that i want to update the user information in a profile Activity if the user wants to change his First name or Last name or something .
But after Clicking save button , the data is saved correctly but the intent never done . it recreate the same Activity .
in the Login activity there is aLogin button which checks username and password then attempt to log in based on data ,if login successful it goes to that Profile Activity .
Save button in Profile Activity re Do the method in Login button in Login Activity which checks everything and goes to Profile Activity which what causing the Re Create Problem .
Here is the code for login button :
MyDatabase = FirebaseDatabase.getInstance().getReference();
MyDatabase.child("USERS").addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
boolean exists = false;
for (DataSnapshot child : dataSnapshot.getChildren()) {
final Map<String, Object> model = (Map<String, Object>) child.getValue();
if (model.get("username").equals(Username.getText().toString())) {
exists = true;
Log.i("USername"," Correct");
if(exists){
MyDatabase.child("USERS").orderByChild("username").equalTo(Username.getText().toString())
.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child :dataSnapshot.getChildren()){
Log.i("Password",child.getValue().toString());
Log.i( "Password",child.child("password").toString());
if(password.getText().toString().equals(child.child("password").getValue())){
Log.i("LOGIN","Success");
loginsuccessful = true ;
if(loginsuccessful){
saveCredntials(Username.getText().toString(),password.getText().toString());
Intent i2 = new Intent(getApplicationContext(), ProfileActivity.class);
i2.putExtra("loginStats",IsLoggedIn);
i2.putExtra("Username",Un);
i2.putExtra("Password",Pw);
startActivity(i2);
finish();}
}else{
Log.i("LOGIN","Failed");
loginsuccessful= false ;
}
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
}
});
}
break;
}else {
Log.i("LOGIN","FAiled");
}
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Sorry for making this too long but i dont know the problem .

Related Links

Android generated Base64 audio file not playing in iOS
Gradle Build Exception : AAPT process not ready to receive commands
What is best solution file upload for python server
React Native app (background job) autostart on phone restart or app crash
Mobile Hub Sample App Google Sign -in canceled if applicationId changes
Return a List of Object from a List of Optional objects
Dagger 2 injection of fields inside classes other than Activities
Getting Binary XML file line #141: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
Can I keep fix the same resolution of the same image when the devices have different densities?
Display the total amount from TextView values in a Custom Listview
How to stop Intent Service in middle of my program?
Which video server to used for videos uploading app?
Android Multiple Button Press
Android studio - SQL Server Connection dependent on the android version?
Google Maps not working on iOS and TestFlight
Application is crashing when it was installed from Android Studio (only on android 5 and less)

Categories

HOME
xml
eclipse
zend-framework
jelastic
jsf-2.2
spring-data-redis
carousel
interpolation
boto3
bing-maps
arangodb
windows-ce
symmetricds
scrolltop
android-intent
mvc-mini-profiler
breadth-first-search
undertow
babel
libigl
href
systemtime
inno-download-plugin
imageresizer
scriptella
perlbrew
ckfinder
jasmine-node
openmdao
user-defined-functions
bioinformatics
turfjs
glib
parse-tree
openalpr
z-notation
watchface
apriori
datacachefactory
outputcache
opencmis
vaadin-elements
reportservice2010
mschart
tinymce-3
trojan
reindex
universal-analytics
gets
usart
cudd
pytables
webjars
preprocessor
synonym
nservicebus5
cassia
html-to-pdf
mobiledoc-kit
inf
concurrentmodification
linklabel
rewrite
poppler
page.js
coda
typemock
baasbox
skspritenode
ansi
user-permissions
procedural-programming
mass-assignment
ejb-2.x
punycode
trdion2011
cancellation
xml-dsig
jjaql
alternate
ios8-extension
dot42
buffering
spring-remoting
embedded-fonts
ie8-compatibility-mode
chart-director
booksleeve
correlated-subquery
denied
entitydatasource
massive
tmx
google-wave
online-storage

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile