launchModes,singleTask:如何QUOT之间的切换和;屏幕"?是意图的唯一途径,如果是这样,我认为我有一个问题我有、是这样、我认为、一个问题

由网友(装作不在意)分享简介:在许多问题(like这个)我一直在寻找到我的应用程序如何换屏。我有在顶部的头,有4个按钮。每个按钮是为了取代内容(即切换画面):In a number of questions (like this one) I have been looking into how to "change screens" in my...

在许多问题(like这个)我一直在寻找到我的应用程序如何换屏。我有在顶部的头,有4个按钮。每个按钮是为了取代内容(即切换画面):

In a number of questions (like this one) I have been looking into how to "change screens" in my app. I have a "header" on top, with 4 buttons. Each button is meant to replace the "content" (ie change screen):

+--------------------+
| menu with buttons  |
+--------------------+
|                    |
|                    |
|  C O N T E N T     |
|                    |
|                    |
+--------------------+

当我点击菜单按钮,我运行下面的code:

When I click a Menu button, I run the following code:

@Override
public void onClick(View v)
{
    Intent myIntent = new Intent(BaseActivity.this, ActivityMain.class);
    BaseActivity.this.startActivity(myIntent);
}

正如你所看到的, startActivity 的执行。现在,如果我不指定launchMode的活动就意味着launchMode =正常。如果launchMode ==正常,这意味着该活动将每一个我用导航头球顶按键时重新创建,这意味着在表单元素输入的所有数据都消失了(或者至少是隐藏的)。

As you can see, the startActivity is executed. Now, if I do not specify "launchMode" for the Activity that means that launchMode = normal. If launchMode == normal that means that the Activity will be re-created each and every time I navigate using the top header buttons, and that means that all data entered in "form elements" are gone (or at least hidden).

所以,我觉得这听起来有点漂亮的launchModesingleTask。如果我说launchMode添加到我的活动,它不会被重新创建时,我的按钮导航,从而保持状态。大!好了,直到我读这:

So, I found the launchMode "singleTask" that sounded sort of nice. If I add that launchMode to my Activity, it will not be re-created when I navigate with the buttons, thus keeping state. Great! Well, until I read this:

的如上所述,从未有一个singleTask或singleInstance活动的多个实例,以便实例预期处理所有新的意图。的

我发现这句话意味着,也只能有一个具有launchMode设置为singleTask活动 - 如果我有一个以上的它不会工作(没有编译器错误虽然)。

I found out that the sentence mean that there can be only one Activity that has the launchMode set to "singleTask" - if I have more than one it wont work (no compiler error though).

这意味着我只能保持状态我的屏幕之间的一个活动,来回切换时(导航)!

Once一次,这真的是它如何工作的?

Once again, is this really how it supposed to work?

推荐答案

您似乎是强迫的活动存在,他们不应该。

You seem to be forcing activities to exist where they shouldn't.

如果你要使用的按钮作为人造的标签,那么就应该有一个活动,没有 startActivity()通话,并使用 ViewFlipper 的FrameLayout 或东西来改变你的内容相匹配的按钮。毕竟,这是标签是如何工作的,只是因为你选择不使用 TabHost / TabActivity 但滚你自己的标签式的系统,设计的方法应该是一样的。

If you are going to use buttons as faux tabs, then there should be one activity, no startActivity() calls, and use ViewFlipper or a FrameLayout or something to change your content to match the button. After all, this is how tabs work, and just because you are electing not to use TabHost/TabActivity but roll your own tab-esque system, the design approach should be the same.

阅读全文

相关推荐

最新文章