Android Studio - Global Variables

Foreword:
When completing the design, you need to use the value of user id between each interface. At the beginning, it is convenient to use public static to declare the id, and then when entering the next interface, directly use the id declared in this interface Equal to the id of the previous interface

But the disadvantages of doing this appear, because there are situations where you can enter this interface from multiple interfaces, and this method will not work at this time, and sometimes there are other values ​​that need to be passed. It seems very messy when time comes and goes.

Then I thought of using an entity class data to store all the used values, so that each interface can only pass the id of the data through putExtra and getIntent. All the data you want.

Summary:
If the data is relatively small, you can directly use the intent.putExtra method, as long as the putExtra between each interface uses the same name, so no matter which interface you enter from, you can get the desired value, and you can also return to the corresponding interface.

If there is a lot of data, if you think that the intent.putExtra is too much and too troublesome, you can use an entity class to store it, so that you only need to pass the did between the interfaces.

Supongo que te gusta

Origin blog.csdn.net/zzzzzwbetter/article/details/130227205
Recomendado
Clasificación