0

So, I have this app with 4 different activities:

  • A is the main activity with three buttons to launch B, C and D (I think people use to refer to these as sub activities).
  • Each activity has its own layout, but I believe that this is not relevant here.

What I want to do is the standard behaviour for most apps. That is:

  1. I start by launching the app and seeing activity A.
  2. Then I press a button, C, for instance, and activity C is shown.
  3. Then I press the back button and activity A is shown again.

My app does points 1 and 2 correctly, but on 3 the app disappears.

The onClick method of the buttons has something like this:

startActivity(new Intent(this,C.class));

None of the activities overrides the onBackPressed method.

Here is (part of) my manifest file:

<activity android:name=".A" android:label="A" android:launchMode="standard" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

<activity android:name=".B" android:label="B" android:launchMode="standard" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"/>
<activity android:name=".C" android:label="C" android:launchMode="standard" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"/>
<activity android:name=".D" android:label="D" android:launchMode="standard" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait"/>

I know from debug work I've done, that A.onDestroy() is called after the onClick method of a button is called. Based on this info, I think that, and of course I might be wrong, activity A is removed from history stack by the OS for some reason.

Now I know that this kind of issue has already been addressed here on stackoverflow, but I've tried all the suggestions I could find and none worked. I wanted to explain my own case.

4

1 に答える 1

0

もちろん、私は何か間違ったことをしているはずです。

私は onWindowFocusChanged メソッドをオーバーライドし、そこでアクティビティを破棄していたので、もちろんスタックから削除されていました。

@stefan と @colegu の時間を無駄にして申し訳ありません。

于 2012-02-29T09:23:00.203 に答える