0

I have two activity. One of these is a sort of home activity (with some choises) and the other is the main activity. Use do this:

<activity
            android:name=".Home"
            android:label="@string/app_name"
            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=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
        </activity>

And in Home.java i set:

@Override
    protected void onPause() {
        super.onPause();
        finish();
    }

    @Override
    protected void onStop() {
        super.onStop();
        finish();
    }

In MainActivity.java I do nothing in method onPause() and onStop(). The problem is that if in MainActivity I set back, the app is in my background app and I can see the screen of MainActivity.

But when I restart the app, it restart with Home.

Well, how can I restart with MainActivity? Thanks

Marcus
  • 6,697
  • 11
  • 46
  • 89
pippo15
  • 113
  • 1
  • 4
  • 17
  • 2
    Switch them in your manifest if you want `MainActivity` to be the launcher. Or else I don't understand your issue completely. – codeMagic Feb 20 '15 at 16:15
  • as @codeMagic said, if you want `MainActivity` as launcher, you have to switch them. – Blackbelt Feb 20 '15 at 16:16
  • You do not have to call _finish()_ from _onStop()_ – 18446744073709551615 Feb 20 '15 at 16:19
  • I want that the first activity is Home activity. So Launcher is home activity. But when I clicked back button, I will see in background app MainActivity's screen. But when I clicked to resume it will open Home activity – pippo15 Feb 20 '15 at 16:36
  • You can use a boolean to check in home activity and according to this if it is true then redirect to mainactivity otherwise homeactivity. And boolean value should be set when first time you go to mainactivity from home. – Surender Kumar Feb 20 '15 at 16:37
  • I learn a thing: if I do finish() the app wasn't destroy! Probably if I do finish() the app will be on background restarted! I don't know because I'm a new android developper... Do you think that is better to destroy the app and not finished? – pippo15 Feb 20 '15 at 16:45

2 Answers2

0

If you want your application to always launch from MainActivity you need to move the intent-filter to it in the manifest file.

    <activity
        android:name=".Home"
        android:label="@string/app_name"
        android:screenOrientation="portrait">
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

You are also getting this behavior because you are calling finish() in your onStop(). As described here you are forcing a onDestroy() in your onStop().

Community
  • 1
  • 1
mziemer
  • 338
  • 3
  • 13
0

Try this:

@Override
protected void onPause() {
super.onPause();
system.exit(0);
}
QArea
  • 4,955
  • 1
  • 12
  • 22