Kai
Kai

Reputation: 3865

Start an app by long-pressing home button always restarts the app instead of bring it to foreground

My app has two activities, ActivityA and ActivityB. They are specified in AndroidManifest below:

<activity android:name=".ActivityA" android:label="@string/app_name" android:screenOrientation="landscape" 
    android:configChanges="orientation|keyboardHidden|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>
<activity android:name=".ActivityB" 
    android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden|screenSize" 
    android:windowSoftInputMode="stateAlwaysHidden"/>

The scenario of the problem is below.

  1. I start the app and ActivityA shows.
  2. From ActivityA, I start ActivityB and close ActivityA. Now the task stack only contains ActivityB.
  3. I press Home button, then the phone goes to home screen.
  4. I long-press Home button, and pick up my app from the history.
  5. After step 4, ActivityA starts and shows, and the task stack contains ActivityA at top and ActivityB at the bottom.

I am very confused at step 5. What I expected is that, the app will be brought to foreground with its existing task stack, i.e. with only ActivityB in the task stack. Why does Android start ActivityA at step 5?

BTW, the client logs contains the message below at Step 5:

10-26 21:29:04.070 V/HtcAppUsageStats( 275): (launch app, package): (MyApp, com.example.myapp)

10-26 21:29:04.070 I/ActivityManager( 275): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x34500000 cmp=com.example.myapp/.ActivityA bnds=[0,566][540,662] (has extras) } from pid 275

Thanks for any suggestions!

Upvotes: 1

Views: 723

Answers (2)

Ali Ashraf
Ali Ashraf

Reputation: 1919

Ok, so if you want to have an Activity not to show on long pressing home button:

  1. Start that activity as intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);

  2. In android Manifest for that activity android:excludeFromRecents="true"

You can follow this link as well This should solve your problem !!!

Upvotes: 0

Kai
Kai

Reputation: 3865

ahhhh, I saw this Android bug, http://code.google.com/p/android/issues/detail?id=26658. It seems to be the root cause.

Upvotes: 1

Related Questions