为什么活动是悬而回来,从另一个活动的几个片段?几个、片段

2023-09-13 02:18:08 作者:住在你城里的不是我

我有两个活动,活动A和B,活动A有3个片段,即A1,A2和A3。 A3是默认选择的片段显示视频,A2包含一个大的TextView和一个小的EditText它和A1包含ListView。

I have two activities Activity A and B, Activity A has 3 fragments namely a1,a2 and a3. a3 is the default selected fragment which shows videos, a2 contains one big textView and a small edittext in it and a1 contains a listview.

现在在活动A的标题栏我有一个按钮,因为它是在标题栏是从所有3个片段可见。该按钮的OnClick我用下面的函数打开活动B.。

Now On activity A's title bar I have a button, and since it is on title bar it is visible from all 3 fragments. OnClick of this button I open Activity B. using Following function.

public void inviteUser() {
    if ( getUserType() == ACTIVE ) {
        Intent intent = new Intent(this, B.class);
        intent.putExtra(Constants.MEETING_ID, (long) session.getSessionId());
        intent.putExtra(Constants.INVITE_FROM_SESSION, true);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        this.startActivityForResult(intent, RESULT_OK);
    } else {
        Toast.makeText(this, getString(R.string.strNotAPresenterMsg), Toast.LENGTH_LONG).show();
    }
}

在BI调用它的的setResult(结果code)和面漆()。现在我的两个问题:当我的的的片段A1和A2,入门C 的

Inside B I call its setResult(ResultCode) and finish(). Now I have two problems when I start B from Fragments a1 and a2,

当我开始活动的的从片段A3 B,的它立即返回,行为正常。

when I start the activity B from fragment a3, it returns immediately and behaves normally.

我试图重写这些片段的所有生命周期方法,并把日志报表的每个方法中。疼痛是该方法的调用顺序是正常的,相同的两个案件。

I have tried overriding all the life cycle methods of these fragments and put the Log statements inside each method. Pain is that method calling sequence is normal and same for both the cases.

我试图改变的意图,但没有收获的标志。

I have tried changing the flags of the intent but to no gain.

我已经加入falg 安卓configChanges =keyboardHidden |定位我的应用程序的所有活动。

I have added falg android:configChanges="keyboardHidden|orientation" for all the activities of my app.

希望我解释这个问题,如果任何一个需要的code的任何特定部分。请comment.I将编辑的问题,并补充说。帮助家伙!

Hope I explained the problem, in case any one need any specific part of the code. please comment.I will edit the question and add that. Help guys!!!

修改 我在测试中的姜饼2.3.6它不工作,但我只是检查了在模拟器上运行软糖,这是工作的罚款。貌似问题与操作系统版本。你知道吗?

EDIT I was testing in GingerBread 2.3.6 it was not working but I just checked that on emulator running JellyBean and it is working fine. Looks like the issue is related to OS version. Any idea ?

编辑2 观察一重要的一点是,当在BI preSS后退按钮时,几毫秒后previous活性的onResume()和它们的片段被调用。但即使在那之后B是在屏幕上了一段时间,这似乎是电话挂了几秒钟......

EDIT 2 One important point of observation is that When in B I press back button, after few mili seconds the onResume() of Previous Activity and their fragments are called. But even after that B is on Screen for some time and that seems like phone hanged for few seconds....

修改3 也是刚刚才知道的onStop()和B的OnDestroy()的时候,我从片段开始对B不叫A1或A2。但是他们被称为完美的,当我在A3。可能是什么原因呢?

EDIT 3 Just got to know that onStop() and OnDestroy() of B are not called when I start the B from Fragment a1 or a2. However They are called perfectly when I am on a3. What could be the reason for this ?

该文档称,一个活动的可视生命周期),直到到的onStop(相应的调用调用ONSTART()之间发生的情况。在此期间,用户可以看到屏幕上的活动,虽然它可能不前景和与用户交互。

The doc says that "The visible lifetime of an activity happens between a call to onStart() until a corresponding call to onStop(). During this time the user can see the activity on-screen, though it may not be in the foreground and interacting with the user."

由于的onStop()不保证该活动运行不正常,那就不叫。我也才知道,在蜂窝+设备,它总是被调用。我已经打过电话的onStop()内的onPause(),但不工作。我现在怎么办?

Since onStop() is not guaranteed the activity behaves abnormally when it is not called.. I also came to know that in HoneyComb+ devices it is always called. I have tried calling onStop() inside onPause() but that is not working. What I do now ?

推荐答案

这真的很难,我来解释我的问题,以SO社区,甚至难以被理解问题的根源,但一旦我找到了误差源,它只是花了几个分钟来解决这个问题。

It was really hard for me to explain my problem to SO community and even harder was to understand the problem source but once I tracked the error source it just took few mins to solve the problem.

该问题是由于包含的布局(比如X)在活动的   布局视图。在X的知名度正在决定当前   分段。这是在A3和View.GONE其他两个片段可见。一世   除去从a1和a2和问题布局解决了...

The problem was due to an included layout (say x) in the Activity's layout view. The x's visibility was being decided on the current fragment. It was visible on a3 and View.GONE on other two fragments. I removed that layout from a1 and a2 and the problem was solved...

不过,我仍然无法理解它必须涉及与B的的onStop和的onDestroy而现在被称为完美......如果任何人都可以找到比请分享..

However I still can't understand what it has to relate with the B's onStop and onDestroy which are now being called perfectly... If anyone can find than please share..

希望的信息可以帮助别人,

Hope the information can be helpful for someone else,