Я использую MVP в своем приложении. Я получаю сообщение об ошибке
Error reporting crash
android.os.TransactionTooLargeException: data parcel size 1052448 bytes
Я знаю, что этот вопрос уже задавался, но другое решение не работает для меня.Моя активность - вход пользователей в firebase с помощью кнопки входа в Google
это код докладчика:
View view;
private final static int RC_SIGN_IN = 2;
//TODO : try to find a way to edit this use
FirebaseUser currentUser;
GoogleApiClient mGoogleApiClient;
public GeneralSignActivityPresenter(View view){
this.view = view;
}
public void signInWithGoogle(String requestIdToken) {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(requestIdToken)
.requestEmail()
.build();
if(mGoogleApiClient == null || !mGoogleApiClient.isConnected()){
mGoogleApiClient = new GoogleApiClient.Builder((Context) view)//TODO : check this context, TODO : check why this variable isn't used
.enableAutoManage((FragmentActivity) view, new GoogleApiClient.OnConnectionFailedListener() {//TODO : check this casting
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
view.onGoogleConnectionFailed();
Log.v("Logging", "connection result is : " + connectionResult.toString());
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API)
.build();
}
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient((Context) view, gso);//TODO : check this context
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
view.startSignIntent(signInIntent);
}
public void navigate(final String userType) {
currentUser = FirebaseAuth.getInstance().getCurrentUser();
String currentUserUid = currentUser.getUid();
final DatabaseReference usersReference = FirebaseDatabase.getInstance().getReference("users");
final DatabaseReference currentUserReference = usersReference.child(currentUserUid);
usersReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (!dataSnapshot.child(currentUser.getUid()).exists()) {
Map<String, Object> map = new HashMap<>();
map.put("userName", currentUser.getDisplayName());
map.put("userImage", currentUser.getPhotoUrl());
map.put("userEmail", currentUser.getEmail());
map.put("points", 0);
map.put("acceptedQuestions", 0);
map.put("refusedQuestions", 0);
map.put("acceptedLessons", 0);
map.put("refusedLessons", 0);
map.put("userType", userType);
usersReference.child(currentUser.getUid()).setValue(map);
}
else {
//TODO : check if this part is working or no
currentUserReference.child("userName").setValue(currentUser.getDisplayName());
currentUserReference.child("userImage").setValue(currentUser.getPhotoUrl());
currentUserReference.child("userType").setValue(userType);
}
view.goToMainActivity();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
public void checkCurrentUser(){
if (currentUser != null) {
view.goToMainActivity();
}
}
public interface View {
void onGoogleConnectionFailed();
и код активности:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_general_sign);
ButterKnife.bind(this);
FirebaseApp.initializeApp(this);
presenter = new GeneralSignActivityPresenter(this);
button = findViewById(R.id.googleBtn);
userTypesSpinner = findViewById(R.id.userTypesSpinner);
unStudentSignAlertText = findViewById(R.id.unStudentSignAlertText);
ArrayAdapter<CharSequence> userTypesAdapter = ArrayAdapter.createFromResource(this,
R.array.user_types_array, android.R.layout.simple_spinner_item);
userTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
userTypesSpinner.setAdapter(userTypesAdapter);
userTypesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
userType = adapterView.getItemAtPosition(i).toString();
if (userType.equals("طالب")) {
unStudentSignAlertText.setVisibility(View.GONE);
} else {
unStudentSignAlertText.setVisibility(View.VISIBLE);
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
/* mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = findViewById(R.id.facebookBtn);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "facebook:onSuccess:" + loginResult);
Toast.makeText(GeneralSignActivity.this, "onSuccess" + loginResult, Toast.LENGTH_SHORT).show();
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Log.d(TAG, "facebook:onCancel");
Toast.makeText(GeneralSignActivity.this, "onCancel" , Toast.LENGTH_SHORT).show();
// ...
}
@Override
public void onError(FacebookException error) {
Log.d(TAG, "facebook:onError", error);
Toast.makeText(GeneralSignActivity.this, "onError : " + error, Toast.LENGTH_SHORT).show();
// ...
}
});*/
// ...
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
presenter.signInWithGoogle(getString(R.string.default_web_client_id));
}
});
mCallbackManager = CallbackManager.Factory.create();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
auth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
presenter.navigate(userType);
} else {
// If sign in fails, display a message to the user.
Toast.makeText(GeneralSignActivity.this, "فشل التسجيل في التطبيق قد يكون لديك مشكلة في الإتصال بالانترنت أو أن إدارة البرنامج قامت بإلغاء تفعيل حسابك", Toast.LENGTH_SHORT).show();
//updateUI(null);
}
// ...
}
});
//Toast.makeText(this, "نجح تسجيل الدخول",Toast.LENGTH_SHORT).show();
} catch (ApiException e) {
Toast.makeText(GeneralSignActivity.this, "حدث خطأ أثناء محاولة التسجيل برجاء اعادة المحاولة", Toast.LENGTH_SHORT).show();
}
}//TODO
// mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onStart() {
super.onStart();
//TODO : note : don't try to update the users data here again
presenter.checkCurrentUser();
}
@Override
public void onGoogleConnectionFailed() {
Toast.makeText(GeneralSignActivity.this, "حدث خطأ برجاء إعادة المحاولة", Toast.LENGTH_SHORT).show();
}
@Override
public void goToMainActivity() {
startActivity(new Intent(GeneralSignActivity.this, MainActivity.class));
}
@Override
public void startSignIntent(Intent signInIntent) {
startActivityForResult(signInIntent, RC_SIGN_IN);
}
void goToMainActivity();
void startSignIntent(Intent signInIntent);
}
Я много пытался решить эту ошибку, но я не посылаю большие данные между классами, я не могу понять, в чем проблема.