0

I have an app that goes to the homeScreen when I click the back button in certain activity using a Galaxy SII (Android 4.0.4) but it does goes back normally to all the previous activities that not call the finish() method when using an HTC EVO (Android 2.3.5).

I was thinking it was an android version feature and now I am more secure it is. I tried using the emulator in those version and the result was the same. It's an android version problem.

Here I attach the images, so it could be clear what's the problem.

Main Screen Second Activity enter image description here enter image description here

If I click the back button at this position, it takes me out of the app to the home screen. That is with the Galaxy S3

But with the android 2.3.5, this is how it works.

enter image description here enter image description here enter image description here enter image description here

In the 2.3.5 version, I click back, an every activity is back at the foreground. Any clue about that problem?

The code of the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.silm.sfa"
android:versionCode="2"
android:versionName="1.1" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:name="com.silm.sfa.app.App"
    android:allowBackup="true"
    android:icon="@drawable/sfa_new_version_logo"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar" >
    <activity
        android:name=".Splash"
        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=".Login"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar" >
    </activity>
    <activity
        android:name=".Prefs"
        android:label="@string/config"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".Summary"
        android:label="@string/resumen"
        android:theme="@android:style/Theme.Dialog" 
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name="com.jvra.signature.SignatureActivity"
        android:configChanges="orientation"
        android:theme="@android:style/Theme.Dialog"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".System"
        android:theme="@android:style/Theme.NoTitleBar"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".find.Finder"
        android:configChanges="orientation"
        android:theme="@android:style/Theme.NoTitleBar"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".Dashboard"
        android:theme="@android:style/Theme.NoTitleBar"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".Help"
        android:label="@string/help"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".bprocess.OrdersRecipe"
        android:label="@string/help"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".bprocess.DebitNotesProcess"
        android:label="@string/help"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".bprocess.CreditNotesProcess"
        android:label="@string/help"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".bprocess.StatementProcess"
        android:label="@string/help"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".bprocess.Products"
        android:label="@string/help"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".signature.SignatureActivity"
        android:label="@string/help"
        android:screenOrientation="landscape" >
    </activity>
</application>

</manifest>

Code of the back button method:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{

    if( event.getAction() == KeyEvent.ACTION_DOWN )
        if( keyCode == KeyEvent.KEYCODE_BACK )
        {
            DetailFragment detail = (DetailFragment) getSupportFragmentManager().findFragmentByTag(FIND_DETAIL_FRAGMENT);
            if( detail != null && detail.isVisible() )
                searchBar.setEnabledSearchButton(true);
        }
    return super.onKeyDown(keyCode, event);
}
Sterling Diaz
  • 3,789
  • 2
  • 31
  • 35

2 Answers2

1

Try with this ;)

@Override       
public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) 
        {
            // Call main activity or whatever you want :)
        }

        return super.onKeyDown(keyCode, event);
    }

You must call this method in every activity.

1

You must overwrite your onBackPressed method. Just put this before the onCreate method

@Override
public void onBackPressed() {
    Intent mIntent = new Intent(ActualActivity.this, PreviousActivity.class);
    ActualActivity.this.startActivity(mIntent);
    ActualActivity.this.finish();
}