Java Android意图和此新意图的对象(实例)
我对Android编程有一个理解上的问题 当我想在我的应用程序上添加标签时,我会使用我的标签和与这些标签相关的意图来创建代码 现在,我将获得由我的选项卡创建的活动的实例。(检索公共选项卡字段(例如2)并与启动sight TabHost的“我的活动”中的3.All公共字段连接) 如何做到这一点而不使用静态 提前谢谢大家,,Java Android意图和此新意图的对象(实例),java,android,android-intent,Java,Android,Android Intent,我对Android编程有一个理解上的问题 当我想在我的应用程序上添加标签时,我会使用我的标签和与这些标签相关的意图来创建代码 现在,我将获得由我的选项卡创建的活动的实例。(检索公共选项卡字段(例如2)并与启动sight TabHost的“我的活动”中的3.All公共字段连接) 如何做到这一点而不使用静态 提前谢谢大家,, Julien.您是否对每个选项卡使用不同的活动 如果是,并将字段视为字符串,在示例2中: Intent intent = new Intent(this, Yo
Julien.您是否对每个选项卡使用不同的活动 如果是,并将字段视为字符串,在示例2中:
Intent intent = new Intent(this, YourThirdActivity.class);
intent.putExtra("Field2", field2.toString());
在示例3中:
intent = getIntent();
Field2 = intent.getStringExtra("Field2");
我认为这不是最好的解决方案,但它确实有效:
public class Tab2 extends Activity {
static Tab2 Instance;
protected void onCreate(Bundle savedInstanceState) {
Instance = this;
{...}
public class TabMain extends TabActivity {
protected void onCreate(Bundle savedInstanceState) {
{... Create and launch all Intent Tab ...}
String value = Tab2.Instance.MyMethodReturnSomeThing();
{...}
public class Tab2 extends Activity {
static Tab2 Instance;
protected void onCreate(Bundle savedInstanceState) {
Instance = this;
{...}
public class TabMain extends TabActivity {
protected void onCreate(Bundle savedInstanceState) {
{... Create and launch all Intent Tab ...}
String value = Tab2.Instance.MyMethodReturnSomeThing();
{...}
目前,这是我的解决方案。
如果你最好想一想://谢谢你的回答,事实上问题不在于这个。将创建my Intent to my tab的活动必须检索选项卡中存在的字段(实际上这是字符串、URI、速率(带星星))(因此,在由我的选项卡创建的活动中)。我意识到我可以把一些东西从我的“TabMain”传递到我的“Tab1”,Tab2,“Tab3”,但我会做相反的事情,从“Tab1”,Tab2,“Tab3”中检索数据,因为我的“TabMain”!我不知道我是否清楚,越过语言障碍不利于我!谢谢你的帮助!