Question

I have two textViews in different activity A and B that need to have the same Value. I can not use putExtra because I am not going from Activity A to B. I do not want to use Shared Preferences. I do not want to put then query from a sqlite. Is there a way for me to call for the Text in Activity A when I am on Activity B ?

I am able to get the Layout value of Activity A from Activity B but not the text Value in a textView of Activity A

In Activity B

Name1.setText(R.layout.menuview);

That will give me the name value of the xml file. I want the value of a this textView inside the xml file.

In Activity A

m1a = (TextView) findViewById(R.id.m1a);
Was it helpful?

Solution

why cant u use shared preference?
you can use static variable and keep value in memory.

OTHER TIPS

You could use a static variable on a helper class.

public class Helper { static String text; }

The way that one activity changes view property directly by reference of another activity isn't good way. Because activity should reference another one, it is reason of memory leak.

I suggest below ways

1) LocalbroadcastReceiver

If you use this, dependency is gone between the activities. Also you can observe changing in real time. But some codes be added.

2) SharedPreference

It is another alternative methods, but it use disk io and disk space. If you have to save values permanently, using this way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top