• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

App Inventor How to make a text view equal to firebase string

Cinemato

Lurker
May 22, 2020
3
0
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:
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 :)
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones