M
M
Maxim Zelenkov2014-02-03 13:01:10
Android
Maxim Zelenkov, 2014-02-03 13:01:10

How to transfer data from one Activity to two at once?

Hello, I started writing an application for Android and I had a question, how to transfer data from one Activity to two at once ?
I will describe my task more precisely, I have the first activity MainActivity, by clicking on the button another activity opens VremActivitywith inheritance from tabActivity
Here is the code:

public class VremActivity extends TabActivity {
    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.vrem);
            
            // получаем TabHost
            TabHost tabHost = getTabHost();
            
            // инициализация была выполнена в getTabHost
            // метод setup вызывать не нужно
            
            TabHost.TabSpec tabSpec;
            
            tabSpec = tabHost.newTabSpec("tag1");
            tabSpec.setIndicator("Вкладка 1");
            tabSpec.setContent(new Intent(this, OneActivity.class) );
            tabHost.addTab(tabSpec);
            
            tabSpec = tabHost.newTabSpec("tag2");
            tabSpec.setIndicator("Вкладка 2");
            tabSpec.setContent(new Intent(this, TwoActivity.class));
            tabHost.addTab(tabSpec);
        }
    }

This activity displays two activities OneActivityand in the tabs. TwoActivity
So, from the activity MainActivityyou need to transfer data to OneActivityand TwoActivity.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
one pavel, 2014-02-03
@st1nger757

You create internal Activities through Intents, so pass the incoming data to these Intents.

C
constv, 2014-02-03
@constv

in the VremActivity class create a public method that returns what needs to be passed to OneActivity and TwoActivity, for example getFirstParam()
in OneActivity and TwoActivity respectively call this method

Log.i("MyLog", "firstParam=" +((VremActivity )this.getParent()).getFirstParam());

S
svd71, 2014-02-04
@svd71

Does it make sense for you to split into different Activiti? It may be easier to do without Intent and process it in one Java class, changing only the layout form on demand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question