Search code examples
androidandroid-activityactivity-finish

App re-open on same activity issue


I have 3 Activities, Activity1, Activity2 and Activity3. when app goes to background it always open from same activity. for example Activity1 is a Launcher Activity, than navigate to Activity2, now I pressed HOME Button and app goes to background, and whenever app re-opens it open Activity2. But on some devices (Samsung S5) i got problem, when App is on Activity2, Pressed Home button than re-open app it always open Activity1 which is launcher Activity. But I want when App re-open it will open same Activity where it was on last time.

Activity2 Code Below

public class Activity2 extends Activity{
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity2);
}

public void onActivity1(View view){
    Intent mainIntent = new Intent(this, Activity1.class);
    mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    mainIntent.putExtra("EXIT", true);
    startActivity(mainIntent);
    Settings.this.finish();
}

public void onActivity3(View view) {
Intent infoIntent = new Intent(this, Activity3.class);
infoIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
infoIntent.putExtra("EXIT", true);
    startActivity(infoIntent);
    Settings.this.finish();
}
}

Below is manifest code

<activity
        android:name=".SplashScreen"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Activity1"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait"
        android:stateNotNeeded="true"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:windowSoftInputMode="stateAlwaysHidden" >
    </activity>
    <activity
        android:name=".Activity2"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    </activity>
    <activity
        android:name=".Activity3"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
    </activity>

Solution

  • I think it is not possible since background activity can be killed by the system at any arbitrary time due to memory issue or some other reason. If your activity is killed by the OS, you can't get it back to the previous status (in here Activity2). Actually this is not device issue, it may depends on the device specifications, specially like memory.