Answer the question
In order to leave comments, you need to log in
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 VremActivity
with 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);
}
}
OneActivity
and in the tabs. TwoActivity
MainActivity
you need to transfer data to OneActivity
and TwoActivity
.
Answer the question
In order to leave comments, you need to log in
You create internal Activities through Intents, so pass the incoming data to these Intents.
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());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question