Reputation: 458
Whenever I press the back button from any activity in my app it jumps straight to the home screen. I was under the impression that I could set hierarchical parents using the manifest. Here is part of my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.spicycheesecake.slidr" >
...
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainMenu"
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=".Tutorial"
android:parentActivityName=".MainMenu"
android:screenOrientation="portrait" />
...
</application>
Here is the code for the activity:
package com.spicycheesecake.slidr;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;
public class Tutorial extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tutorial);
((TextView)findViewById(R.id.tutorialView)).setText(Html.fromHtml(getString(R.string.how_to_play)));
}
}
I am aware that onBackPressed()
can be overridden, but I want to know why this isn't working.
My min sdk is 16 btw.
Upvotes: 0
Views: 64
Reputation: 171
If you haven't specified a parent activity you should be returned to the calling activity when you exit the previous one (and since you have one declared it should return you to it anyways). So the behavior of your app is really odd.
Could it be that you have overwritten onBackPressed()
or onDestroy()
?
EDIT: I mean the onBackPressed()
and onDestroy()
of your called activity, Tutorial in this case.
Yes, this should be a comment, but I don't have the rep for it. Sorry
Upvotes: 0
Reputation: 86
If you have finished your activity when you called:
startActivity(intent);
finish();
This will destroy the current activity and going to next. So when you press back it will go back to the last not destroyed.
Try to take out your line of code:
finish();
Upvotes: 2