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.










share|improve this question









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














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.










share|improve this question









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












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.










share|improve this question









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 android firebase firebase-realtime-database






share|improve this question









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.











share|improve this question









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.









share|improve this question




share|improve this question








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
















  • 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












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.






share|improve this answer




















  • 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










  • Okay thank you. It works now
    – Samiirah Aujub
    yesterday

















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.






share|improve this answer




















  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Samiirah Aujub is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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






























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.






share|improve this answer




















  • 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










  • Okay thank you. It works now
    – Samiirah Aujub
    yesterday














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.






share|improve this answer




















  • 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










  • Okay thank you. It works now
    – Samiirah Aujub
    yesterday












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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 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
















  • 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










  • 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












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.






share|improve this answer




















  • 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














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.






share|improve this answer




















  • 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












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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










Samiirah Aujub is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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.













 


draft saved


draft discarded














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














































































Popular posts from this blog

27

Top Tejano songwriter Luis Silva dead of heart attack at 64

Category:Rhetoric