简体   繁体   English

我如何通过使用Intent从Android中的另一个常规活动中调用特定的选项卡活动

[英]How can i call a specific tab activity from another regular activity in android by using intent

I have 3 tabs (act1,act2,act3) and i have activities without tabs(A,B), if the user open activity A and press button OK then alarm will start and after 10 seconds it will go to act2 我有3个标签页(act1,act2,act3),并且我有没有标签页(A,B)的活动,如果用户打开活动A并按OK,则警报将启动,并在10秒钟后进入act2

this all done, but i tried many thing : 这一切都完成了,但是我尝试了很多事情:

1- when i go to act2 it does not display the tabs. 1-当我去act2时,它不显示选项卡。 just act2 activity 只是act2活动

so i change the code and tried to : 2- when i go to activity tabs it show me the first tab(act1) but i wanna act2 所以我更改代码并尝试执行以下操作:2-当我转到活动选项卡时,它向我显示了第一个选项卡(act1),但我想使用act2

how can i do it i wanna display act2 with tab 我该怎么办我想显示带选项卡的act2

Give me any reference or hint. 给我任何参考或提示。
Thanks in Advance. 提前致谢。

Try this: Send an intent (via startActivity() as usual) to bring the activity to the front which contains the tabs. 尝试以下操作:发送意图(照常通过startActivity())将活动带到包含选项卡的前面。 Send an extra parameter with the activity containing the TAG or some identifier for tab, you want to be opened. 发送一个额外的参数,其中包含要打开的标签或标签的标识符的活动。 Evaluate the extra parameter in the activity, which contains the tab and let it switch to the tab as indicated by the parameter. 评估活动中的额外参数,该参数包含选项卡,并使其切换到该参数所指示的选项卡。

EDIT 编辑

To start the tab activity with a parameter: 要使用参数启动选项卡活动:

final Intent i = new Intent(this, YourTabActivity.class);
i.putExtra(TAB_TAG, tag);  // TAB_ID see comment below, define some tags for the tabs
this.startActivity(i);

To extract the parameter from the intent: 要从意图中提取参数:

Overwrite onNewIntent() in the tab activity and introduce a field lastIntent , set this.lastIntent = this.getIntent() there. 在选项卡活动中覆盖onNewIntent()并引入一个字段lastIntent ,在this.lastIntent = this.getIntent()设置this.lastIntent = this.getIntent() (Otherwise you will always access the intent which started the activity in the first place, not the most recently sent intent!) (否则,您将始终访问从头开始活动的意图,而不是最近发送的意图!)

in onResume process the last intent: onResume流程中,最后一个意图是:

final Bundle extras = this.lastIntent.getExtras();
final String tabTag = extras.getString(TAB_TAG);    // define the key TAB_TAG as static string

Now use tabTag to set the current tab. 现在使用tabTag设置当前选项卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM