Back Button Exits App,而不是进行以前的活动



我有许多从注册到登录等的活动设置。我尝试过Backped((,但似乎对我不起作用。在此阶段,我不会通过工具栏实现后箭头。

有人可以帮助我吗?我的活动之一下面是代码。

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:fitsSystemWindows="true">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="@drawable/shape_gradient_orange"
        android:orientation="vertical">
        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_marginTop="20dp"
            android:layout_gravity="center"
            android:src="@drawable/search_icon" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_gravity="center"
            android:text="@string/app_full_name"
            android:textColor="#FAFAFA"
            android:textSize="20sp" />
    </LinearLayout>
    <android.support.v7.widget.CardView
        android:layout_width="350dp"
        android:layout_height="220dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="160dp"
        android:background="@drawable/border"
        android:id="@+id/cardView">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:padding="10dp"
                android:text="@string/logIn"
                android:textSize="20dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <EditText
                    android:id="@+id/employerEmailAddress"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:layout_gravity="center"
                    android:layout_marginTop="15dp"
                    android:background="#FAFAFA"
                    android:singleLine="true"
                    android:drawableLeft="@mipmap/email_icon"
                    android:drawablePadding="10dp"
                    android:hint="@string/employerEmailAddress"
                    android:maxLines="1"
                    android:textSize="15sp" />
                <EditText
                    android:id="@+id/employerPassword"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:layout_gravity="center"
                    android:inputType="textPassword"
                    android:layout_marginTop="15dp"
                    android:singleLine="true"
                    android:background="#FAFAFA"
                    android:drawableLeft="@mipmap/password_icon"
                    android:drawablePadding="10dp"
                    android:hint="@string/employerPassword"
                    android:maxLines="1"
                    android:textSize="15sp" />

            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_below="@+id/cardView"
        android:gravity="center"
        android:orientation="vertical"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/button"
            android:layout_width="200dp"
            android:layout_marginTop="10dp"
            android:textColor="#FAFAFA"
            android:layout_height="wrap_content"
            android:text="Log in"
            android:background="@drawable/shape_gradient_orange"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/haveAccount"
            android:textColor="#999"
            android:padding="10dp"
            android:text="@string/signUpMessage"/>
    </LinearLayout>

</RelativeLayout>
</LinearLayout>

这是我的Java代码 - 示例非常简单的活动。

package com.example.dennis.discover;
 import android.content.Intent;
 import android.nfc.Tag;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
 import android.view.WindowManager;
 import android.widget.TextView;
 public class EmployerLogIn extends AppCompatActivity {
private TextView haveAccount;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_employer_log_in);

    haveAccount = (TextView) findViewById(R.id.haveAccount);
    haveAccount.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent employerSignUp = new Intent(EmployerLogIn.this, 
   EmployerSignUp.class);
            startActivity(employerSignUp);
            finish();
            }
        });
     }
 }

startActivity(employerSignUp);

之后删除finish()

最新更新