Hello.

I use the intent transfer the data to the variable entered in edittext for the second activation and there I work with the variable containing this data.

Tell me how to transfer from the first activation these data to three activations at once, two of which are used as tabs (tabactivity)?

As I understand it, the usual startActivity cannot do that in this case, all the specified activations open at once and the program crashes.

I was looking for a solution on the Internet and stumbled upon the use of singleton , but I did not find a good job description in Russian. Can you also share a link to a Russian-language resource or tell about the principle of singleton ?

    2 answers 2

    1. TabActivity , as tabs are already outdated. Fragments are now used for this.
    2. In the main activity ( ActivityGroup ?) You store links to child activites? If so, then define a method in the children that accepts the desired variable as a parameter and performs all the necessary operations, and call this method in the main activation, where you need to pass some value to the children. And if you do not store, then save, and do as described above.

    But I would advise you not to use the “stone ax”, but to switch to using fragments.

    • I figured it out myself, but thanks for the hint fragments. - Xetag

    WAT ???)))

    TabActivity - This class was deprecated in API level 13.

    I think it should be so - one activity. on the first snippet TextView and data entry. Further, the magic button was pressed and tabs appeared - which will switch 3 fragments (instead of activities). contain data from TextView should be active and in turn distribute to fragments on demand.

    On the good interface should be written with which this mechanism will be implemented. example -

     interface DataProvider{ String getData() } class MainActivity extend Activity implements DataProvider{ private String data; @Ovveride public String getData(){ return data; } } 

    at fragments

     class TabFragment extend Fragment { private DataProvider provider; onAttach(Context ctx){ if (ctx instancOf DataProvider){ this.provider = ctx; } } onDetach(Context ctx){ provider = null; } } } 

    Well, when the fragment needs to get the data, pull the provider.getData();

    can also be implemented for two activities. on one data entry is carried out then we throw an intent. we start the second. and in this case the second activity will be the provider.

    wrote the code right here so don’t hope for performance)))