tags:

views:

41

answers:

2

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.

A: 

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?

Mayra
I'm only setting singleTask on Activity A. I'm not setting anything for B or C.
cbursk
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.
Mayra
@Mayra - 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.
cbursk
Perhaps you should post your relevant code, manifest, parts of Activity C, etc.
Mayra
@Mayra, thanks for your insights, I've decided to leave the Home button functionality as is for now.
cbursk
A: 

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
@Matt - 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.
cbursk
@Matt, 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] }
cbursk
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!
cbursk