-4

I am new to Android Development and I have this problem of opening another activity from the main activity.

The problem is that whenever I click on the button, the app closes.

Below is my Java code.

package com.Notely.SplashScreenandAccounts;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class ActivityWelcome extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome);
    Button signup_btn = (Button) findViewById(R.id.signup_btn);
    signup_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openActivity2();
        }
    });
}
public void openActivity2() {
    Intent intent = new Intent(this, ActivitySignup.class);
    startActivity(intent);
}
}

I need suggestions on what is the problem and on how to rectify that.

1 Answers1

1

You should add your Activity(ActivitySignup.class) in your AndroidManifest file. Like this..

<Activity android:name = .ActivituSignup android:theme="AppTheme"/>

i hope this will help you .

If it not works you should add this line in your ActivitySignup.java at on create before super.onCreate()

setTheme(R.style.AppCompat);

send your logcat error to understanding best.

You should take a tour of Activity in android.developers.com web