Cinemato
Lurker
Hello, I'm making a project using android studio and java. I have some data in a realtime firebase database and I'm trying to take the data in an activity then making a text view in another activity have the value of that data. I was able to get the data but I when I try to set the textview to equal to it, it does not change.. its like the value is null. I tried printing the value to know if it is null or not and it appeared okay so I dont know the problem.. heere is the code:
Here is the first class that takes the data and sends it:
I realllllly need help so anything is appreciated
Java:
public class HistoryActivity extends AppCompatActivity {
TextView history;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
history = (TextView) findViewById(R.id.historyText);
showHistory();
}
void showHistory()
{
String history_text = getIntent().getStringExtra("HISTORY");
System.out.println(history_text); //DEBUG
history.setText(history_text);
}
}
Here is the first class that takes the data and sends it:
Java:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootNode = FirebaseDatabase.getInstance();
reference = rootNode.getReference("CompanyInfo");
historyBtn = (Button) findViewById(R.id.historyBtn);
addressBtn = (Button) findViewById(R.id.addressBtn);
supportBtn = (Button) findViewById(R.id.supportBtn);
visionBtn = (Button) findViewById(R.id.visionBtn);
Query getTxt = reference;
getTxt.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists())
{
historyTxt = dataSnapshot.child("History").child("Text").getValue(String.class);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
historyBtn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(getApplicationContext(), HistoryActivity.class);
intent.putExtra("HISTORY", historyTxt);
startActivity(intent);
}
});
I realllllly need help so anything is appreciated