0

I am trying to solve an issue sort of similar to what was done here (link text)

Except in my case where Activity A, started Activity B, started Activity C, when the user resumes the app after pressing the home button - I want C, the last Activity, to be displayed. Instead what is happening is I am back to A.

Also on a side note I have discovered that even when I exit the application, if I hold down the Home button, my app is still listed as an active app even though in the LogCat I can see that it exited OK.

Also, in case it matters, I did recently add android:launchMode ="singleTask" in order to make some notification logic work correctly. I was seeing the Home button behavior before that though.

I really appreciate any ideas you might have.

[edit - adding some code snippets]

        <activity 
              android:name         =".connection.ActivityA"
              android:label        ="@string/app_name"
              android:configChanges="orientation|keyboardHidden"
              android:theme        ="@android:style/Theme.NoTitleBar"
              android:launchMode   ="singleTask"
              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         =".screens.AvtivityB"
              android:label        ="@string/app_name"
              android:configChanges="orientation|keyboardHidden"
              android:theme        ="@android:style/Theme.NoTitleBar"
              android:launchMode   ="singleTask"
              android:screenOrientation="portrait"  >
    </activity>

    <activity android:name         =".screens.ActivityC"
              android:label        ="@string/app_name"
              android:configChanges="orientation|keyboardHidden"
              android:theme        ="@android:style/Theme.NoTitleBar"
              android:screenOrientation="portrait" >
    </activity>

Then here is how I kick off each Activity: In Activity A:

private void startActivityB() { Intent activityBIntent = new Intent(this, ActivityB.class); this.startActivityForResult(activityBIntent , ACTIVITYB_TAG); }

Activity B actually has several Activities that it chooses from (it has a list of Intents) to display based on input it receives but launches them all the same way as Activty A launched B. Once the first Activity is displayed the user swipe the screen to navigate to the left or right screen. When the user swipes left or right, the current activity puts info in its return Intent that Activity B uses to display the next Activity. Also since logic outside of the user's control could prompt a change in the screen displayed, each Activty calls finish on itself in onStop to avoid back-button issues.

Community
  • 1
  • 1
bursk
  • 1,647
  • 7
  • 25
  • 39

3 Answers3

2

When you long press home it is showing a list of recently active applications, not applications that are currently running. So you should still see your app in the list, even if it is closed.

As the docs note:

The other modes — singleTask and singleInstance — are not appropriate for most applications, since they result in an interaction model that is likely to be unfamiliar to users and is very different from most other applications.

I'd imagine that your using singleTask is affecting the history stack, and thus preventing Activity C from being remembered. If you remove that from Activity C, does it resolve the problem?

Otherwise, I'd look at what you are doing in onPause/onDestroy etc for Activity C. Are you doing something that would cause it to finish or close?

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
  • I'm only setting singleTask on Activity A. I'm not setting anything for B or C. – bursk Sep 23 '10 at 17:57
  • Ok, I haven't played around with singleTask much...from the docs it looks like you should be ok, but as a trial I'd remove it and see if that fixes your behavior. That should at least give you some information on where to focus your efforts. If its not the problem, then you need to look at what you are doing in Activity C that might cause it to exit prematurely. – Cheryl Simon Sep 23 '10 at 18:17
  • I removed the call to singeTask on Activity A and still get the same behavior. I'm not overriding onPause or onDestroy in Activitys B or C. – bursk Sep 27 '10 at 16:34
  • Perhaps you should post your relevant code, manifest, parts of Activity C, etc. – Cheryl Simon Sep 27 '10 at 17:09
  • thanks for your insights, I've decided to leave the Home button functionality as is for now. – bursk Oct 04 '10 at 19:51
0

Do you get this behavior only when running from Eclipse?

Check your "Run Configurations". There is a "Launch Action" that can be set to "Do Nothing".

Matt

Matt
  • 4,261
  • 4
  • 39
  • 60
  • Thanks for your suggestion! I was actually just re-looking at this issue since it really annoys me. I have pulled up my Run config as you suggested and the Launch action is set to Launch Default Activity. Interesting... I will definitely check this out further this morning. Thanks so much. I'll post follow up comments in a few hours. – bursk Oct 20 '10 at 12:26
  • I was and am still seeing the same behavior whether I install and run from Eclipse or by clicking on my app's icon to run. In my Logcat I can see my poller continuing to run and Activity C receiving the data. I hold down the Home button and get the popup with the app icons. When I select mine the logcat is showing the ActivityManager "Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10100000 cmp=com/ActivityA bnds=[3,238][77,317] } – bursk Oct 20 '10 at 13:31
  • I'll edit my original post and see if I can add some code snippets in. I'm having similar issues with notifications. I really believe that they are related. Thanks! – bursk Oct 20 '10 at 13:34
0

I'm not sure this is what it happening to you, but the answer below solved my problem and I wanted the same behavior as you - that is, getting to the same activity when re-opening after home has been pushed (though in my case, I did actually want the first activity, just not a new one):

Save activity state in android when home button pressed

Now I realize you want to keep the activity stack intact and not go to the first activity like me. But if it is the same problem, then it is not from the fact that the activity stack is torn down, but because a new one (with the opening activity) is added when re-opening after home has been pressed on first install. I hope this is fairly legible, even though I (clearly) found it difficult to explain.

Edit: This is better described here and here.

Community
  • 1
  • 1
DuneCat
  • 788
  • 6
  • 17