Values of override method not reflecting on main variables
up vote
0
down vote
favorite
I am trying to change values of my class from an override method as shown below:
public class QuestionAnalyser extends AppCompatActivity
String question;
String entityIdentified;
static boolean identified = false;
DatabaseReference entityRef;
TranslatorServant t = new TranslatorServant();
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_interface);
public void analyse(String userQues)
if (!(Interface.deviceLang.equals("en")))
TranslatorServant t = new TranslatorServant();
question = t.translateText(userQues);
else
question = userQues;
question = question.replaceAll("\pPunct
private void getEntity(final String words)
entityRef = FirebaseDatabase.getInstance().getReference().child("IRAdata").child("Entities");
entityRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
for (DataSnapshot entity : dataSnapshot.getChildren())
String synonyms = entity.child("syn").getValue().toString().split(",");
for (String syn : synonyms)
for (String word : words) question.equalsIgnoreCase(syn))
mimicOtherMessage("found");
entityIdentified = entity.getKey();
identified = true;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
Toast.makeText(getApplicationContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
);
if (identified == false)
for (String yes : YesNo.yes)
for (String w : words)
for (String no : YesNo.no)
for (String w : words)
if (w.equalsIgnoreCase(no)
return;
From the analyse() method i am calling the getEntity() method, the override method is working fine and is changing the value of identified and entityIdentified accordingly but, when the method is completed the updates are not reflected on the variables.
I have tried to debug, i could see the values changing in the override method, but when i check the values of the variables after the override method, i could only get the initial values. Somebody can help me on this please?
I have tried implementing threads as well, to make sure the method getEntity() gets completed before returning to the main, but the problem persists.
java
New contributor
Samiirah Aujub is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I am trying to change values of my class from an override method as shown below:
public class QuestionAnalyser extends AppCompatActivity
String question;
String entityIdentified;
static boolean identified = false;
DatabaseReference entityRef;
TranslatorServant t = new TranslatorServant();
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_interface);
public void analyse(String userQues)
if (!(Interface.deviceLang.equals("en")))
TranslatorServant t = new TranslatorServant();
question = t.translateText(userQues);
else
question = userQues;
question = question.replaceAll("\pPunct
private void getEntity(final String words)
entityRef = FirebaseDatabase.getInstance().getReference().child("IRAdata").child("Entities");
entityRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
for (DataSnapshot entity : dataSnapshot.getChildren())
String synonyms = entity.child("syn").getValue().toString().split(",");
for (String syn : synonyms)
for (String word : words) question.equalsIgnoreCase(syn))
mimicOtherMessage("found");
entityIdentified = entity.getKey();
identified = true;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
Toast.makeText(getApplicationContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
);
if (identified == false)
for (String yes : YesNo.yes)
for (String w : words)
for (String no : YesNo.no)
for (String w : words)
if (w.equalsIgnoreCase(no)
return;
From the analyse() method i am calling the getEntity() method, the override method is working fine and is changing the value of identified and entityIdentified accordingly but, when the method is completed the updates are not reflected on the variables.
I have tried to debug, i could see the values changing in the override method, but when i check the values of the variables after the override method, i could only get the initial values. Somebody can help me on this please?
I have tried implementing threads as well, to make sure the method getEntity() gets completed before returning to the main, but the problem persists.
java
New contributor
Samiirah Aujub is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Need more clarification on your question. entityIdentified = entity.getKey(); //changed here but not after this method completes identified = true; //changed here but not after this method completes In override method OnDataChange() ?
– Ashutoshg
Nov 10 at 10:52
when i am checking the values of the global variables after the override method OnDataChange(), the updates are not reflecting.
– Samiirah Aujub
Nov 10 at 11:21
You are doing the changes with the assumption that your variables will be assigned instantly, from top to down, however, you should remember that the network operation with Firebase is running concurrently on a separate thread which might finish later. So you are seeing the variables being set, but they are set after the Firebase operation is done, which is independent of you code flow.
– Cool Guy CG
Nov 10 at 15:48
Thank you for your answer @CoolGuyCG . I was suspecting something like this was happening but was not sure.
– Samiirah Aujub
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to change values of my class from an override method as shown below:
public class QuestionAnalyser extends AppCompatActivity
String question;
String entityIdentified;
static boolean identified = false;
DatabaseReference entityRef;
TranslatorServant t = new TranslatorServant();
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_interface);
public void analyse(String userQues)
if (!(Interface.deviceLang.equals("en")))
TranslatorServant t = new TranslatorServant();
question = t.translateText(userQues);
else
question = userQues;
question = question.replaceAll("\pPunct
private void getEntity(final String words)
entityRef = FirebaseDatabase.getInstance().getReference().child("IRAdata").child("Entities");
entityRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
for (DataSnapshot entity : dataSnapshot.getChildren())
String synonyms = entity.child("syn").getValue().toString().split(",");
for (String syn : synonyms)
for (String word : words) question.equalsIgnoreCase(syn))
mimicOtherMessage("found");
entityIdentified = entity.getKey();
identified = true;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
Toast.makeText(getApplicationContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
);
if (identified == false)
for (String yes : YesNo.yes)
for (String w : words)
for (String no : YesNo.no)
for (String w : words)
if (w.equalsIgnoreCase(no)
return;
From the analyse() method i am calling the getEntity() method, the override method is working fine and is changing the value of identified and entityIdentified accordingly but, when the method is completed the updates are not reflected on the variables.
I have tried to debug, i could see the values changing in the override method, but when i check the values of the variables after the override method, i could only get the initial values. Somebody can help me on this please?
I have tried implementing threads as well, to make sure the method getEntity() gets completed before returning to the main, but the problem persists.
java
New contributor
Samiirah Aujub is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am trying to change values of my class from an override method as shown below:
public class QuestionAnalyser extends AppCompatActivity
String question;
String entityIdentified;
static boolean identified = false;
DatabaseReference entityRef;
TranslatorServant t = new TranslatorServant();
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_interface);
public void analyse(String userQues)
if (!(Interface.deviceLang.equals("en")))
TranslatorServant t = new TranslatorServant();
question = t.translateText(userQues);
else
question = userQues;
question = question.replaceAll("\pPunct
private void getEntity(final String words)
entityRef = FirebaseDatabase.getInstance().getReference().child("IRAdata").child("Entities");
entityRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
for (DataSnapshot entity : dataSnapshot.getChildren())
String synonyms = entity.child("syn").getValue().toString().split(",");
for (String syn : synonyms)
for (String word : words) question.equalsIgnoreCase(syn))
mimicOtherMessage("found");
entityIdentified = entity.getKey();
identified = true;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
Toast.makeText(getApplicationContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
);
if (identified == false)
for (String yes : YesNo.yes)
for (String w : words)
for (String no : YesNo.no)
for (String w : words)
if (w.equalsIgnoreCase(no)
return;
From the analyse() method i am calling the getEntity() method, the override method is working fine and is changing the value of identified and entityIdentified accordingly but, when the method is completed the updates are not reflected on the variables.
I have tried to debug, i could see the values changing in the override method, but when i check the values of the variables after the override method, i could only get the initial values. Somebody can help me on this please?
I have tried implementing threads as well, to make sure the method getEntity() gets completed before returning to the main, but the problem persists.
java
java
New contributor
Samiirah Aujub is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Samiirah Aujub is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 10 at 15:35
Frank van Puffelen
218k25361385
218k25361385
New contributor
Samiirah Aujub is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 10 at 10:27
Samiirah Aujub
34
34
New contributor
Samiirah Aujub is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Samiirah Aujub is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Samiirah Aujub is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Need more clarification on your question. entityIdentified = entity.getKey(); //changed here but not after this method completes identified = true; //changed here but not after this method completes In override method OnDataChange() ?
– Ashutoshg
Nov 10 at 10:52
when i am checking the values of the global variables after the override method OnDataChange(), the updates are not reflecting.
– Samiirah Aujub
Nov 10 at 11:21
You are doing the changes with the assumption that your variables will be assigned instantly, from top to down, however, you should remember that the network operation with Firebase is running concurrently on a separate thread which might finish later. So you are seeing the variables being set, but they are set after the Firebase operation is done, which is independent of you code flow.
– Cool Guy CG
Nov 10 at 15:48
Thank you for your answer @CoolGuyCG . I was suspecting something like this was happening but was not sure.
– Samiirah Aujub
2 days ago
add a comment |
Need more clarification on your question. entityIdentified = entity.getKey(); //changed here but not after this method completes identified = true; //changed here but not after this method completes In override method OnDataChange() ?
– Ashutoshg
Nov 10 at 10:52
when i am checking the values of the global variables after the override method OnDataChange(), the updates are not reflecting.
– Samiirah Aujub
Nov 10 at 11:21
You are doing the changes with the assumption that your variables will be assigned instantly, from top to down, however, you should remember that the network operation with Firebase is running concurrently on a separate thread which might finish later. So you are seeing the variables being set, but they are set after the Firebase operation is done, which is independent of you code flow.
– Cool Guy CG
Nov 10 at 15:48
Thank you for your answer @CoolGuyCG . I was suspecting something like this was happening but was not sure.
– Samiirah Aujub
2 days ago
Need more clarification on your question. entityIdentified = entity.getKey(); //changed here but not after this method completes identified = true; //changed here but not after this method completes In override method OnDataChange() ?
– Ashutoshg
Nov 10 at 10:52
Need more clarification on your question. entityIdentified = entity.getKey(); //changed here but not after this method completes identified = true; //changed here but not after this method completes In override method OnDataChange() ?
– Ashutoshg
Nov 10 at 10:52
when i am checking the values of the global variables after the override method OnDataChange(), the updates are not reflecting.
– Samiirah Aujub
Nov 10 at 11:21
when i am checking the values of the global variables after the override method OnDataChange(), the updates are not reflecting.
– Samiirah Aujub
Nov 10 at 11:21
You are doing the changes with the assumption that your variables will be assigned instantly, from top to down, however, you should remember that the network operation with Firebase is running concurrently on a separate thread which might finish later. So you are seeing the variables being set, but they are set after the Firebase operation is done, which is independent of you code flow.
– Cool Guy CG
Nov 10 at 15:48
You are doing the changes with the assumption that your variables will be assigned instantly, from top to down, however, you should remember that the network operation with Firebase is running concurrently on a separate thread which might finish later. So you are seeing the variables being set, but they are set after the Firebase operation is done, which is independent of you code flow.
– Cool Guy CG
Nov 10 at 15:48
Thank you for your answer @CoolGuyCG . I was suspecting something like this was happening but was not sure.
– Samiirah Aujub
2 days ago
Thank you for your answer @CoolGuyCG . I was suspecting something like this was happening but was not sure.
– Samiirah Aujub
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
The code you have written is not very detailed to me, but your logic could be restructured in a way, similar to what I have done below:
public class QuestionAnalyser extends AppCompatActivity
String question;
String entityIdentified;
static boolean identified = false;
DatabaseReference entityRef;
TranslatorServant t = new TranslatorServant();
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_interface);
public void analyse(String userQues) \d", "");
final String words = question.split(" ");
getEntity(words);
// remove any logic that depends on the return of getEntity(words) from here
// it is best if the logic is called from within the Firebase call
private void getEntity(final String words)
entityRef = FirebaseDatabase.getInstance().getReference().child("IRAdata").child("Entities");
entityRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
for (DataSnapshot entity : dataSnapshot.getChildren())
String synonyms = entity.child("syn").getValue().toString().split(",");
for (String syn : synonyms)
for (String word : words)
if (word.equalsIgnoreCase(syn)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
Toast.makeText(getApplicationContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
);
// the logic here will have to also be moved into the Firebase call
Note that, the parts that required the check on identified have all been moved to the onDataChanged method.
Yes, i get your point. But what if i need the on change method to be completed first before i proceed? Is there a way to put the firebase method execution in a thread and ensure the thread is executed first then resumes with the main?
– Samiirah Aujub
2 days ago
That will cause your application to hang, it is a form of NetworkOnMainThread. You should never tie your application's main thread to a network operation, they should be asynchronous. However, you can move almost all your operations into theonDataChangedmethod, where all your views can be updated with arunOnUIThreadcall.
– Cool Guy CG
2 days ago
Okay thank you. It works now
– Samiirah Aujub
yesterday
add a comment |
up vote
0
down vote
Please move your code written after getEntity()
Inside onDataChange() method. When onDataChange() completes it will execute added code. You will get latest values in variables.
Thank you for your answer, like i mentioned above is there anyway using threads to make sure the onChange() method gets completed before the main thread resumes?
– Samiirah Aujub
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
The code you have written is not very detailed to me, but your logic could be restructured in a way, similar to what I have done below:
public class QuestionAnalyser extends AppCompatActivity
String question;
String entityIdentified;
static boolean identified = false;
DatabaseReference entityRef;
TranslatorServant t = new TranslatorServant();
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_interface);
public void analyse(String userQues) \d", "");
final String words = question.split(" ");
getEntity(words);
// remove any logic that depends on the return of getEntity(words) from here
// it is best if the logic is called from within the Firebase call
private void getEntity(final String words)
entityRef = FirebaseDatabase.getInstance().getReference().child("IRAdata").child("Entities");
entityRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
for (DataSnapshot entity : dataSnapshot.getChildren())
String synonyms = entity.child("syn").getValue().toString().split(",");
for (String syn : synonyms)
for (String word : words)
if (word.equalsIgnoreCase(syn)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
Toast.makeText(getApplicationContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
);
// the logic here will have to also be moved into the Firebase call
Note that, the parts that required the check on identified have all been moved to the onDataChanged method.
Yes, i get your point. But what if i need the on change method to be completed first before i proceed? Is there a way to put the firebase method execution in a thread and ensure the thread is executed first then resumes with the main?
– Samiirah Aujub
2 days ago
That will cause your application to hang, it is a form of NetworkOnMainThread. You should never tie your application's main thread to a network operation, they should be asynchronous. However, you can move almost all your operations into theonDataChangedmethod, where all your views can be updated with arunOnUIThreadcall.
– Cool Guy CG
2 days ago
Okay thank you. It works now
– Samiirah Aujub
yesterday
add a comment |
up vote
0
down vote
accepted
The code you have written is not very detailed to me, but your logic could be restructured in a way, similar to what I have done below:
public class QuestionAnalyser extends AppCompatActivity
String question;
String entityIdentified;
static boolean identified = false;
DatabaseReference entityRef;
TranslatorServant t = new TranslatorServant();
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_interface);
public void analyse(String userQues) \d", "");
final String words = question.split(" ");
getEntity(words);
// remove any logic that depends on the return of getEntity(words) from here
// it is best if the logic is called from within the Firebase call
private void getEntity(final String words)
entityRef = FirebaseDatabase.getInstance().getReference().child("IRAdata").child("Entities");
entityRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
for (DataSnapshot entity : dataSnapshot.getChildren())
String synonyms = entity.child("syn").getValue().toString().split(",");
for (String syn : synonyms)
for (String word : words)
if (word.equalsIgnoreCase(syn)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
Toast.makeText(getApplicationContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
);
// the logic here will have to also be moved into the Firebase call
Note that, the parts that required the check on identified have all been moved to the onDataChanged method.
Yes, i get your point. But what if i need the on change method to be completed first before i proceed? Is there a way to put the firebase method execution in a thread and ensure the thread is executed first then resumes with the main?
– Samiirah Aujub
2 days ago
That will cause your application to hang, it is a form of NetworkOnMainThread. You should never tie your application's main thread to a network operation, they should be asynchronous. However, you can move almost all your operations into theonDataChangedmethod, where all your views can be updated with arunOnUIThreadcall.
– Cool Guy CG
2 days ago
Okay thank you. It works now
– Samiirah Aujub
yesterday
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
The code you have written is not very detailed to me, but your logic could be restructured in a way, similar to what I have done below:
public class QuestionAnalyser extends AppCompatActivity
String question;
String entityIdentified;
static boolean identified = false;
DatabaseReference entityRef;
TranslatorServant t = new TranslatorServant();
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_interface);
public void analyse(String userQues) \d", "");
final String words = question.split(" ");
getEntity(words);
// remove any logic that depends on the return of getEntity(words) from here
// it is best if the logic is called from within the Firebase call
private void getEntity(final String words)
entityRef = FirebaseDatabase.getInstance().getReference().child("IRAdata").child("Entities");
entityRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
for (DataSnapshot entity : dataSnapshot.getChildren())
String synonyms = entity.child("syn").getValue().toString().split(",");
for (String syn : synonyms)
for (String word : words)
if (word.equalsIgnoreCase(syn)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
Toast.makeText(getApplicationContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
);
// the logic here will have to also be moved into the Firebase call
Note that, the parts that required the check on identified have all been moved to the onDataChanged method.
The code you have written is not very detailed to me, but your logic could be restructured in a way, similar to what I have done below:
public class QuestionAnalyser extends AppCompatActivity
String question;
String entityIdentified;
static boolean identified = false;
DatabaseReference entityRef;
TranslatorServant t = new TranslatorServant();
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_interface);
public void analyse(String userQues) \d", "");
final String words = question.split(" ");
getEntity(words);
// remove any logic that depends on the return of getEntity(words) from here
// it is best if the logic is called from within the Firebase call
private void getEntity(final String words)
entityRef = FirebaseDatabase.getInstance().getReference().child("IRAdata").child("Entities");
entityRef.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
for (DataSnapshot entity : dataSnapshot.getChildren())
String synonyms = entity.child("syn").getValue().toString().split(",");
for (String syn : synonyms)
for (String word : words)
if (word.equalsIgnoreCase(syn)
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
Toast.makeText(getApplicationContext(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
);
// the logic here will have to also be moved into the Firebase call
Note that, the parts that required the check on identified have all been moved to the onDataChanged method.
answered Nov 10 at 16:11
Cool Guy CG
69548
69548
Yes, i get your point. But what if i need the on change method to be completed first before i proceed? Is there a way to put the firebase method execution in a thread and ensure the thread is executed first then resumes with the main?
– Samiirah Aujub
2 days ago
That will cause your application to hang, it is a form of NetworkOnMainThread. You should never tie your application's main thread to a network operation, they should be asynchronous. However, you can move almost all your operations into theonDataChangedmethod, where all your views can be updated with arunOnUIThreadcall.
– Cool Guy CG
2 days ago
Okay thank you. It works now
– Samiirah Aujub
yesterday
add a comment |
Yes, i get your point. But what if i need the on change method to be completed first before i proceed? Is there a way to put the firebase method execution in a thread and ensure the thread is executed first then resumes with the main?
– Samiirah Aujub
2 days ago
That will cause your application to hang, it is a form of NetworkOnMainThread. You should never tie your application's main thread to a network operation, they should be asynchronous. However, you can move almost all your operations into theonDataChangedmethod, where all your views can be updated with arunOnUIThreadcall.
– Cool Guy CG
2 days ago
Okay thank you. It works now
– Samiirah Aujub
yesterday
Yes, i get your point. But what if i need the on change method to be completed first before i proceed? Is there a way to put the firebase method execution in a thread and ensure the thread is executed first then resumes with the main?
– Samiirah Aujub
2 days ago
Yes, i get your point. But what if i need the on change method to be completed first before i proceed? Is there a way to put the firebase method execution in a thread and ensure the thread is executed first then resumes with the main?
– Samiirah Aujub
2 days ago
That will cause your application to hang, it is a form of NetworkOnMainThread. You should never tie your application's main thread to a network operation, they should be asynchronous. However, you can move almost all your operations into the
onDataChanged method, where all your views can be updated with a runOnUIThread call.– Cool Guy CG
2 days ago
That will cause your application to hang, it is a form of NetworkOnMainThread. You should never tie your application's main thread to a network operation, they should be asynchronous. However, you can move almost all your operations into the
onDataChanged method, where all your views can be updated with a runOnUIThread call.– Cool Guy CG
2 days ago
Okay thank you. It works now
– Samiirah Aujub
yesterday
Okay thank you. It works now
– Samiirah Aujub
yesterday
add a comment |
up vote
0
down vote
Please move your code written after getEntity()
Inside onDataChange() method. When onDataChange() completes it will execute added code. You will get latest values in variables.
Thank you for your answer, like i mentioned above is there anyway using threads to make sure the onChange() method gets completed before the main thread resumes?
– Samiirah Aujub
2 days ago
add a comment |
up vote
0
down vote
Please move your code written after getEntity()
Inside onDataChange() method. When onDataChange() completes it will execute added code. You will get latest values in variables.
Thank you for your answer, like i mentioned above is there anyway using threads to make sure the onChange() method gets completed before the main thread resumes?
– Samiirah Aujub
2 days ago
add a comment |
up vote
0
down vote
up vote
0
down vote
Please move your code written after getEntity()
Inside onDataChange() method. When onDataChange() completes it will execute added code. You will get latest values in variables.
Please move your code written after getEntity()
Inside onDataChange() method. When onDataChange() completes it will execute added code. You will get latest values in variables.
answered 2 days ago
Ashutoshg
555
555
Thank you for your answer, like i mentioned above is there anyway using threads to make sure the onChange() method gets completed before the main thread resumes?
– Samiirah Aujub
2 days ago
add a comment |
Thank you for your answer, like i mentioned above is there anyway using threads to make sure the onChange() method gets completed before the main thread resumes?
– Samiirah Aujub
2 days ago
Thank you for your answer, like i mentioned above is there anyway using threads to make sure the onChange() method gets completed before the main thread resumes?
– Samiirah Aujub
2 days ago
Thank you for your answer, like i mentioned above is there anyway using threads to make sure the onChange() method gets completed before the main thread resumes?
– Samiirah Aujub
2 days ago
add a comment |
Samiirah Aujub is a new contributor. Be nice, and check out our Code of Conduct.
Samiirah Aujub is a new contributor. Be nice, and check out our Code of Conduct.
Samiirah Aujub is a new contributor. Be nice, and check out our Code of Conduct.
Samiirah Aujub is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238024%2fvalues-of-override-method-not-reflecting-on-main-variables%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Need more clarification on your question. entityIdentified = entity.getKey(); //changed here but not after this method completes identified = true; //changed here but not after this method completes In override method OnDataChange() ?
– Ashutoshg
Nov 10 at 10:52
when i am checking the values of the global variables after the override method OnDataChange(), the updates are not reflecting.
– Samiirah Aujub
Nov 10 at 11:21
You are doing the changes with the assumption that your variables will be assigned instantly, from top to down, however, you should remember that the network operation with Firebase is running concurrently on a separate thread which might finish later. So you are seeing the variables being set, but they are set after the Firebase operation is done, which is independent of you code flow.
– Cool Guy CG
Nov 10 at 15:48
Thank you for your answer @CoolGuyCG . I was suspecting something like this was happening but was not sure.
– Samiirah Aujub
2 days ago