Android ActivityGroup 应该使用哪个 Intent Flag?
我有一个 TabActivity,第一个选项卡是 ActivityGroup,我为此使用下面的代码;
public class MyTabActivity extends TabActivity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec tabSpec;
Intent intent;
Resources resources = getResources();
intent = new Intent(MyTabActivity.this, MyActivityGroup.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
tabSpec = tabHost.newTabSpec("tab1");
tabSpec.setIndicator("Tab1", resources.getDrawable(R.drawable.ic_launcher));
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
intent = new Intent(MyTabActivity.this, SecondTab.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
tabSpec = tabHost.newTabSpec("tab2");
tabSpec.setIndicator("Tab2", resources.getDrawable(R.drawable.ic_launcher));
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
tabHost.setCurrentTab(0);
}
}
在我的 ActivityGroup
中,我想在单击 button
之后进入另一个 Activity
,因此我使用下面的代码:
public class MyActivityGroup extends ActivityGroup
{
private Button button;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_group);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent intent = new Intent(MyActivityGroup.this, FirstActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
View view = getLocalActivityManager().startActivity("firstActivity", intent).getDecorView();
setContentView(view);
}
});
}
}
它可以工作,但有一个问题,当我在 FirstActivity
中单击第一个选项卡时,我无法转到 MyActivityGroup
。但例如,单击 SecondTab
后,如果我单击第一个选项卡,我可以转到 MyActivityGroup
。
为了解决这个问题,我想我应该改变Intent标志,但我无法做到这一点。请帮我。
I have a TabActivity
and the first tab is an ActivityGroup
and I'm using the code below for this;
public class MyTabActivity extends TabActivity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec tabSpec;
Intent intent;
Resources resources = getResources();
intent = new Intent(MyTabActivity.this, MyActivityGroup.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
tabSpec = tabHost.newTabSpec("tab1");
tabSpec.setIndicator("Tab1", resources.getDrawable(R.drawable.ic_launcher));
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
intent = new Intent(MyTabActivity.this, SecondTab.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
tabSpec = tabHost.newTabSpec("tab2");
tabSpec.setIndicator("Tab2", resources.getDrawable(R.drawable.ic_launcher));
tabSpec.setContent(intent);
tabHost.addTab(tabSpec);
tabHost.setCurrentTab(0);
}
}
And in my ActivityGroup
, I want to go another Activity
after button
click therefore I'm using the code below:
public class MyActivityGroup extends ActivityGroup
{
private Button button;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_group);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent intent = new Intent(MyActivityGroup.this, FirstActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
View view = getLocalActivityManager().startActivity("firstActivity", intent).getDecorView();
setContentView(view);
}
});
}
}
It works but there is a problem, when I click the first tab while in the FirstActivity
, I can not go to MyActivityGroup
. But for example, after clicking SecondTab
, if I click first tab, I can go to MyActivityGroup
.
To solve this problem, I think I should change the Intent flag, but I couldn't manage it. Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能给我看更多吗?我是这样实现的:
您还想查看活动组本身吗?
好的,这是:
Can you show me some more? I had it implemented like this:
Do you also want to see the activitygroup itself?
Ok, here it is:
设置
中
如果它是第一个选项卡,那么应该在......
If it's the first tab, then this should be set in the
..
...