Possuo uma java class denominada Firebase, essa classe só faz funções do firebase...
Eu estou autenticando um novo usuário no firebase, até ai tudo bem.. O problema é que eu não consigo passar para uma outra Activity, está dando o seguinte erro:
05-24 23:56:38.335 15742-15742/com.hotelaria.neoris.checkincheckout E/AndroidRuntime: FATAL EXCEPTION: main Process: com.hotelaria.neoris.checkincheckout, PID: 15742 java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference at android.app.Activity.startActivityForResult(Activity.java:4488) at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:68) at android.app.Activity.startActivityForResult(Activity.java:4445) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:751) at android.app.Activity.startActivity(Activity.java:4806) at android.app.Activity.startActivity(Activity.java:4774) at com.hotelaria.neoris.checkincheckout.models.objects.Firebase$1.onComplete(Firebase.java:35) at com.google.android.gms.tasks.zzf.run(Unknown Source:23) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Firebase.class:
package com.hotelaria.neoris.checkincheckout.models.objects;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.hotelaria.neoris.checkincheckout.activitys.SigninActivity;;
public class Firebase extends AppCompatActivity {
private final FirebaseDatabase mFirebaseDatabase = FirebaseDatabase.getInstance();
private final FirebaseAuth mFirebaseAuth = FirebaseAuth.getInstance();
private final DatabaseReference mDatabaseReference = mFirebaseDatabase.getReference();
public void writeNewUser(final Activity activity, final Context activityContext, String email, String password){
this.mFirebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
Toast toast = Toast.makeText(activityContext,"SUCESSO, CONTA CADASTRADA!", Toast.LENGTH_SHORT);
toast.show();
Intent intent = new Intent(activity.getApplicationContext(), SigninActivity.class);
startActivity(intent);
finish();
} else {
Toast toast = Toast.makeText(activityContext,"OPS ACONTECEU ALGUM ERRO...", Toast.LENGTH_SHORT);
toast.show();
}
}
});
}
}
SignUpActivity.class:
package com.hotelaria.neoris.checkincheckout.activitys;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import com.hotelaria.neoris.checkincheckout.R;
import com.hotelaria.neoris.checkincheckout.models.objects.Firebase;
public class SignupActivity extends AppCompatActivity {
private Firebase mFirebase;
private EditText mEditText;
private ImageButton mImageButton;
private Button mButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
this.onClickButtonBackToLoginActivity();
this.onClickButtonRegisterUser();
}
private void onClickButtonBackToLoginActivity(){
this.mImageButton = findViewById(R.id.imageButtonBackToLoginActivity);
this.mImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SignupActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
});
}
private void onClickButtonRegisterUser(){
this.mButton = findViewById(R.id.buttonRegisterUser);
this.mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Context activityContext = getApplicationContext();
if(checkEditText() == true) {
Toast toast = Toast.makeText(activityContext, "PREENCHA O E-MAIL E A SENHA !!", Toast.LENGTH_SHORT);
toast.show();
} else {
mFirebase = new Firebase();
mFirebase.writeNewUser(SignupActivity.this, activityContext, getEmail(), getPassword());
}
}
});
}
private Boolean checkEditText(){
if(getEmail().isEmpty() || getPassword().isEmpty()){
return true;
} else {
return false;
}
}
private String getEmail(){
this.mEditText = findViewById(R.id.editTextEmail);
return this.mEditText.getText().toString();
}
private String getPassword(){
this.mEditText = findViewById(R.id.editTextPassword);
return this.mEditText.getText().toString();
}
}
SignInActivity.class
package com.hotelaria.neoris.checkincheckout.activitys;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import com.hotelaria.neoris.checkincheckout.R;
public class SigninActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signin);
this.onClickButtonBackToLoginActivity();
this.onClickButtonGoToMainActivity();
}
public void onClickButtonBackToLoginActivity(){
ImageButton imageBtnSignInActivity = findViewById(R.id.imageButtonBackToLoginActivity);
imageBtnSignInActivity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SigninActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
});
}
public void onClickButtonGoToMainActivity(){
Button imageBtnSignInActivity = findViewById(R.id.buttonRegisterUsr);
imageBtnSignInActivity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SigninActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
});
}
}
activity.getApplicationContext()
usa o próprio contexto que você passou, oactivityContext
nesse linha:Intent intent = new Intent(activity.getApplicationContext()...