在活动跳跃中有问题

时间:2014-04-28 09:44:28

标签: android android-activity

我正在开发简单的登录活动。点击发送到下一个屏幕按钮,它必须跳转到另一个活动,但它会出错不幸的是活动已停止工作&关闭我的应用程序如何克服这个问题?

我的第一个活动的java代码是

package com.project.whoami;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class FirstScreenActivity extends Activity {
    EditText inputName;
    EditText inputEmail;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screen1);
    inputName = (EditText) findViewById(R.id.name);
    inputEmail = (EditText) findViewById(R.id.email);
    Button btnNextScreen = (Button) findViewById(R.id.btnNextScreen);

  //Listening to button event
    btnNextScreen.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            //Starting a new Intent
            Intent nextScreen = new Intent(getApplicationContext(), SecondScreenActivity.class);

            //Sending data to another Activity
            nextScreen.putExtra("name", inputName.getText().toString());
            nextScreen.putExtra("email", inputEmail.getText().toString());

            Log.e("n", inputName.getText()+"."+ inputEmail.getText());

            startActivity(nextScreen);

        }
    });
}
}

我的第二个活动的java代码

package com.project.whoami;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class SecondScreenActivity extends Activity {
    public void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.screen2);

        TextView txtName = (TextView) findViewById(R.id.txtName);
        TextView txtEmail = (TextView) findViewById(R.id.txtEmail);
        Button btnClose = (Button) findViewById(R.id.btnClose);

        Intent i = getIntent();
        // Receiving the Data
        String name = i.getStringExtra("name");
        String email = i.getStringExtra("email");
        Log.e("Second Screen", name + "." + email);

        // Displaying Received data
        txtName.setText(name);
        txtEmail.setText(email);

        // Binding Click event to Button
        btnClose.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                //Closing SecondScreen Activity
                finish();
            }

            private void finish() {
                // TODO Auto-generated method stub

            }
        });

    }


}

1 个答案:

答案 0 :(得分:0)

检查你的android清单文件,在那里声明第二个活动..