-3

I'm sure that this will be a really newbie question but I'm stuck and I don't know how to get out of this!

I have an app that have three activities and when I use HOME button and I open the app again, it goes to the FIRST activity always, even if I was in the second or at the third one.

EDIT 3: My app comes in three activities, the first one is the main menu, the second is a map of tables and the third one are the data of the tables. Depending of the configuration, closing the third activity must bring me to the first one or the second one, and when I'm leaving the third Activity I dont want it to stay on the Activities stack. My program is working fine going from an Activity to another one. My problem is that seems that when I use Home Button my app finishes every Activity except the first one.

Maybe I have to modify anything on the manifest or maybe I have to use in a specifically way the RestoreInstanceState but I'm searching so hard and I can't find anything. Thanks in advance!

Edit 1: I'm adding my 'application' xml part of the Manifest:

<application
    android:allowBackup="true"
    android:icon="@drawable/icobaccus"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
        android:name="com.example.tpv2_tablet.Activity_Start"
        android:label="@string/app_name" 
        android:screenOrientation="landscape"
        android:windowSoftInputMode="adjustPan" 
        android:configChanges="keyboardHidden|keyboard"
        android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.tpv2_tablet.Activity_Zonas"
        android:label="@string/app_name" 
        android:screenOrientation="landscape"
        android:windowSoftInputMode="adjustPan" 
        android:configChanges="keyboardHidden|keyboard"
        android:theme="@android:style/Theme.NoTitleBar">
    </activity>
    <activity
        android:name="com.example.tpv2_tablet.PrintDialogActivity"
        android:label="@string/app_name" 
        android:screenOrientation="landscape"
        android:windowSoftInputMode="adjustPan" 
        android:configChanges="keyboardHidden|keyboard"
        android:theme="@android:style/Theme.NoTitleBar">
    </activity>
    <activity
        android:name="com.example.tpv2_tablet.Activity_Mesas"
        android:label="@string/app_name" 
        android:screenOrientation="landscape"
        android:windowSoftInputMode="adjustPan" 
        android:configChanges="keyboardHidden|keyboard">
    </activity>
</application>

Edit 2: Maybe I'm doing something wrong when calling other activities or I'm calling a wrong flag:

Intent intent = new Intent(Activity_1.this, Activity_2.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            finish();
                            startActivity(intent);
Óscar
  • 51
  • 1
  • 11
  • 1
    If you post your code we can help you. But before asking check how `Android Lifecycle` works and try to figure out your problem – hrskrs May 21 '15 at 10:19
  • I checked it and I'm getting a bit confused... what part of the code do u want? Manifest? OnCreate()? – Óscar May 21 '15 at 10:23

2 Answers2

1

Remove

<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>

from all activities except launcher activity

To understand the reason why, read Google Documentation here

remove:

android:noHistory="true"

As this will remove the activity from the activity stack

remove:

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();

from:

Intent intent = new Intent(Activity_1.this, Activity_2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(intent); 

to understand the reason check this answer

Community
  • 1
  • 1
hrskrs
  • 4,447
  • 5
  • 38
  • 52
  • I did but isn't working. I'm getting to the first activity again. I've readed the intent documentation but I haven't found anything clear... – Óscar May 21 '15 at 10:55
  • @Óscar_Rubio remove `android:noHistory="true"` too from activities – hrskrs May 21 '15 at 13:35
  • Seems is working now. I've removed the 'noHistory' and the Intent Filters and is working fine now, just need to fix some problems. Thanks for your patience! (Didn't had to modify the Flags nor the finish()). – Óscar May 21 '15 at 14:14
0

You need to set android:clearTaskOnlaunch="false" in your android manifest.

alian
  • 204
  • 1
  • 12
  • I wrote that on my non-launcher activities but they're working in the same way =/. – Óscar May 21 '15 at 10:34
  • can you add the code block that contains intents and manifest to the post? – alian May 21 '15 at 10:41
  • as @hrskrs said you have to remove MAIN intent filters except from Activity_Start. Also you don't need to set clearTaskOnLaunch to false. because the default value is false – alian May 21 '15 at 10:56
  • @Óscar_Rubio do you have to use finish() and intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); while passing activities. that could be the reason because, you are killing the past activities – alian May 21 '15 at 11:05
  • But if I kill the first activity and I'm at the second one, why when I reopen the app after pressing HOME I'm getting to the first one again? – Óscar May 21 '15 at 11:13
  • because of these lines in manifest, first activity is the default launcher activity. That's why you are getting first one. – alian May 21 '15 at 11:41