I am totally new in Android and learning,and i noticed OnBackPressed
takes you to the previous layout in the game, now i added this code which closes the app at OnBackPressed
@Override
public void onBackPressed() {
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory( Intent.CATEGORY_HOME );
homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homeIntent);
super.onBackPressed();
}
My problem is when you start the game again it takes you back to the previous layout not the main layout. Take for example you have 4 activities, when i start the game it takes me to activity 3 how can i avoid this?
<application
android:allowBackup="true"
android:icon="@mipmap/icon1"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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>
<activity
android:name=".StartGame"
android:label="@string/app_name"
android:screenOrientation="portrait"/>
<activity
android:name=".MathQuestions"
android:label="@string/app_name"
android:screenOrientation="portrait"
/>
<activity android:name=".HighScores"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name=".HowToPlay" >
</activity>
</application>