Data does not save in Firebase

Asked

Viewed 73 times

-2

I’m trying to save data in my Firebase database but the app doesn’t save. I can install, boot the app, and move between pages without an app crash, but I can’t save data.

Before implementing the material design was managing to save the data, now I can no longer save.

From what I’ve already researched it seems to be some problem with the Firebase connection, as it apparently disconnects while the app is running. But I couldn’t find a solution that worked.

I’m using:

  • Java Android
  • Material Design for Android (Java)

What I’ve already tried:

  • Swap Splash Screen image from drawable folder to xxx-hpi mipmap folder;
  • I deleted the project cache;
  • I checked the size of the project, but it’s not very big yet, because I don’t use Fragment or very complex things yet;
  • I uninstalled the app and installed again

Firebase is connected to the project and with Rule write:true

Firebase Connection

Firebase Rules

activity_register_user.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".RegisterUserActivity">

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

        <ImageView
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:contentDescription="@string/txt_description_image"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="32dp"
            android:layout_marginBottom="16dp"
            android:src="@mipmap/ic_icon_round"
            >
        </ImageView>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="20dp"
            android:text="@string/register_title"
            android:textAllCaps="true"
            android:textSize="16sp"
            >
        </TextView>

        <!-- ========= REGISTER RADIO BUTTON TYPE USER ========= -->
        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            >

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

                <com.google.android.material.radiobutton.MaterialRadioButton
                    android:id="@+id/radio_btn_register_user"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/radio_btn_user"
                    android:textSize="10pt"
                    android:layout_marginLeft="35sp"
                    android:layout_marginRight="15sp"
                    />

                <com.google.android.material.radiobutton.MaterialRadioButton
                    android:id="@+id/radio_btn_register_worker"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/radio_btn_worker"
                    android:textSize="10pt"
                    android:layout_marginRight="20sp"
                    />
            </LinearLayout>
        </RadioGroup>

        <!-- ========= REGISTER NAME ========= -->
        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/register_username"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="4dp"
            android:hint="@string/register_username"
            app:endIconMode="clear_text"
            >

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/register_username_edit_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:inputType="textNoSuggestions"
                android:maxLines="1"
                android:maxLength="15"
                />

        </com.google.android.material.textfield.TextInputLayout>

        <!-- ========= REGISTER SURNAME ========= -->
        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/register_surname"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="4dp"
            android:hint="@string/register_surname"
            app:endIconMode="clear_text"
            >

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/register_surname_edit_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:inputType="textNoSuggestions"
                android:maxLines="1"
                android:maxLength="15"
                />

        </com.google.android.material.textfield.TextInputLayout>

        <!-- ========= REGISTER EMAIL ========= -->
        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/regiter_email"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="4dp"
            android:hint="@string/register_email"
            app:endIconMode="clear_text"
            >

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/register_email_edit_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:inputType="textEmailAddress|textNoSuggestions"
                android:maxLines="1"
                />

        </com.google.android.material.textfield.TextInputLayout>

        <!-- ========= REGISTER PHONE ========= -->
        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/register_phone"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="@string/register_phone"
            app:endIconMode="clear_text"
            >

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/register_phone_edit_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:inputType="phone|textNoSuggestions"
                android:maxLines="1"
                android:maxLength="11"
                />

        </com.google.android.material.textfield.TextInputLayout>

        <!-- ========= REGISTER PASSWORD ========= -->
        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/register_password"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="@string/register_password"
            app:endIconMode="password_toggle"
            >

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/register_password_edit_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:inputType="textPassword|textNoSuggestions"
                android:maxLines="1"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                />

        </com.google.android.material.textfield.TextInputLayout>

        <!-- ========= REGISTER BUTTON ========= -->
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent">


            <com.google.android.material.button.MaterialButton
                android:id="@+id/btn_register_user"
                style="@style/Widget.MaterialComponents.Button"
                android:layout_width="match_parent"
                android:layout_height="70dp"
                android:backgroundTint="@color/btn_color"
                android:text="@string/btn_register_user"
                android:textColor="@color/colorPrimary"
                android:layout_alignParentBottom="true"
                />

        </RelativeLayout>

    </LinearLayout>



</ScrollView>

Registeruseractivity.java

package com.empodera;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class RegisterUserActivity extends AppCompatActivity
{
    View view;

    /* Get firebase database instance */
    private FirebaseDatabase database = FirebaseDatabase.getInstance();

    private RadioGroup user, worker;
    private EditText name, surname, email, phone, password;

    private String txt_type_user, txt_worker, txt_name, txt_surname, txt_email, txt_password, txt_phone;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_user);

        name = findViewById(R.id.register_username_edit_text);
        surname = findViewById(R.id.register_surname_edit_text);
        email = findViewById(R.id.register_email_edit_text);
        password = findViewById(R.id.register_password_edit_text);
        phone = findViewById(R.id.register_phone_edit_text);
    }

    public void registerUser(View view)
    {
        String typeUser = "";
        UserApp userApp = new UserApp();
        DatabaseReference databaseReferenceInstance = database.getReference();
        DatabaseReference databaseReference = databaseReferenceInstance.child("user");

        /* VALIDATE IF RADIO BUTTON IS CHECKED
        if(typeUser)
        {
        }
        */

        /* Converting EditText type into String type */
        txt_name = name.getText().toString();
        txt_surname = surname.getText().toString();
        txt_email = email.getText().toString();
        txt_password = password.getText().toString();
        txt_phone = phone.getText().toString();

        /* Select the database instance child user */
        databaseReference = database.getReference("user");

        /* Setting data into ServiceApp class */
        userApp.setName(txt_name);
        userApp.setSurname(txt_surname);
        userApp.setEmail(txt_email);
        userApp.setPhone(txt_phone);
        userApp.setPassword(txt_password);

        /* Transfering data into Firebase object reference */
        userApp.setId(databaseReference.push().getKey());

        /* Data ransfered from object to Firebase database */
        databaseReference.child(userApp.getId()).setValue(userApp);

        Intent activity = new Intent(RegisterUserActivity.this, LoginActivity.class);
        startActivity(activity);
        Toast.makeText(this,"Usuário Cadastrado com Sucesso",Toast.LENGTH_LONG).show();

    }
}

Userapp.java

package com.empodera;

public class UserApp
{
    private String id;
    private String type_user, type_worker;
    private String name, surname,  email, phone, password;

    public UserApp()
    {
        this.id = id;
        this.type_user = type_user;
        this.type_worker = type_worker;
        this.name = name;
        this.surname = surname;
        this.email = email;
        this.phone = phone;
        this.password = password;
    }

    public String getId()
    {
        return id;
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getType_user()
    {
        return type_user;
    }

    public void setType_user(String type_user)
    {
        this.type_user = type_user;
    }

    public String getType_worker()
    {
        return type_worker;
    }

    public void setType_worker(String type_worker)
    {
        this.type_worker = type_worker;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getSurname()
    {
        return surname;
    }

    public void setSurname(String surname)
    {
        this.surname = surname;
    }

    public String getEmail()
    {
        return email;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone)
    {
        this.phone = phone;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }
}

Logcat

2020-04-15 16:16:11.107 27413-27413/? I/com.empodera: Late-enabling -Xcheck:jni
2020-04-15 16:16:11.483 27413-27413/com.empodera I/com.empodera: The ClassLoaderContext is a special shared library.
2020-04-15 16:16:12.242 27413-27413/com.empodera V/FA: Registered activity lifecycle callback
2020-04-15 16:16:12.245 27413-27413/com.empodera I/FirebaseInitProvider: FirebaseApp initialization successful
2020-04-15 16:16:12.415 27413-27413/com.empodera W/com.empodera: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
2020-04-15 16:16:12.415 27413-27413/com.empodera W/com.empodera: Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
2020-04-15 16:16:12.415 27413-27413/com.empodera W/com.empodera: Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
2020-04-15 16:16:12.415 27413-27413/com.empodera W/com.empodera: Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
2020-04-15 16:16:12.415 27413-27413/com.empodera W/com.empodera: Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)
2020-04-15 16:16:12.425 27413-27413/com.empodera V/FA: onActivityCreated
2020-04-15 16:16:12.456 27413-27465/com.empodera V/FA: App measurement collection enabled
2020-04-15 16:16:12.461 27413-27465/com.empodera V/FA: App measurement enabled for app package, google app id: com.empodera, 1:920737313471:android:0d0da5b25ee90997160c0a
2020-04-15 16:16:12.468 27413-27465/com.empodera I/FA: App measurement initialized, version: 21028
2020-04-15 16:16:12.468 27413-27465/com.empodera I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2020-04-15 16:16:12.469 27413-27465/com.empodera I/FA: To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.empodera
2020-04-15 16:16:12.469 27413-27465/com.empodera D/FA: Debug-level message logging enabled
2020-04-15 16:16:12.562 27413-27413/com.empodera W/com.empodera: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2020-04-15 16:16:12.565 27413-27413/com.empodera W/com.empodera: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2020-04-15 16:16:12.648 27413-27413/com.empodera D/OpenGLRenderer: Skia GL Pipeline
2020-04-15 16:16:12.755 27413-27465/com.empodera V/FA: Connecting to remote service
2020-04-15 16:16:12.776 27413-27465/com.empodera V/FA: Detected application was in foreground
2020-04-15 16:16:12.785 27413-27468/com.empodera I/Adreno: QUALCOMM build                   : 12b5963, I6fd668c4d3
    Build Date                       : 10/04/18
    OpenGL ES Shader Compiler Version: EV031.25.03.01
    Local Branch                     : 
    Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.7.2.R1.09.00.00.442.049
    Remote Branch                    : NONE
    Reconstruct Branch               : NOTHING
2020-04-15 16:16:12.785 27413-27468/com.empodera I/Adreno: Build Config                     : S L 6.0.7 AArch64
2020-04-15 16:16:12.786 27413-27468/com.empodera D/vndksupport: Loading /vendor/lib64/hw/gralloc.sdm660.so from current namespace instead of sphal namespace.
2020-04-15 16:16:12.790 27413-27465/com.empodera V/FA: Session started, time: 860356701
2020-04-15 16:16:12.806 27413-27468/com.empodera I/Adreno: PFP: 0x005ff112, ME: 0x005ff066
2020-04-15 16:16:12.820 27413-27468/com.empodera I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2020-04-15 16:16:12.821 27413-27468/com.empodera I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2020-04-15 16:16:12.822 27413-27468/com.empodera I/OpenGLRenderer: Initialized EGL, version 1.4
2020-04-15 16:16:12.822 27413-27468/com.empodera D/OpenGLRenderer: Swap behavior 2
2020-04-15 16:16:12.852 27413-27468/com.empodera D/vndksupport: Loading /vendor/lib64/hw/[email protected] from current namespace instead of sphal namespace.
2020-04-15 16:16:12.854 27413-27468/com.empodera D/vndksupport: Loading /vendor/lib64/hw/gralloc.sdm660.so from current namespace instead of sphal namespace.
2020-04-15 16:16:12.873 27413-27465/com.empodera V/FA: Connection attempt already in progress
2020-04-15 16:16:12.892 27413-27465/com.empodera I/FA: Tag Manager is not found and thus will not be used
2020-04-15 16:16:12.977 27413-27465/com.empodera V/FA: Connection attempt already in progress
2020-04-15 16:16:13.009 27413-27465/com.empodera V/FA: Connection attempt already in progress
2020-04-15 16:16:13.015 27413-27465/com.empodera V/FA: Activity resumed, time: 860356541
2020-04-15 16:16:13.171 27413-27465/com.empodera V/FA: Connection attempt already in progress
2020-04-15 16:16:13.172 27413-27465/com.empodera V/FA: Connection attempt already in progress
2020-04-15 16:16:13.173 27413-27465/com.empodera D/FA: Connected to remote service
2020-04-15 16:16:13.176 27413-27465/com.empodera V/FA: Processing queued up service tasks: 6
2020-04-15 16:16:17.640 27413-27465/com.empodera V/FA: Recording user engagement, ms: 5005
2020-04-15 16:16:17.648 27413-27465/com.empodera V/FA: Activity paused, time: 860361547
2020-04-15 16:16:17.652 27413-27413/com.empodera W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@a248765
2020-04-15 16:16:17.672 27413-27413/com.empodera V/FA: onActivityCreated
2020-04-15 16:16:17.754 27413-27413/com.empodera W/com.empodera: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking)
2020-04-15 16:16:18.095 27413-27465/com.empodera V/FA: Activity resumed, time: 860362006
2020-04-15 16:16:21.441 27413-27465/com.empodera V/FA: Recording user engagement, ms: 3341
2020-04-15 16:16:21.448 27413-27465/com.empodera V/FA: Activity paused, time: 860365347
2020-04-15 16:16:21.450 27413-27413/com.empodera W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@85670f6
2020-04-15 16:16:21.520 27413-27413/com.empodera V/FA: onActivityCreated
2020-04-15 16:16:21.881 27413-27465/com.empodera V/FA: Activity resumed, time: 860365792
2020-04-15 16:16:27.024 27413-27465/com.empodera V/FA: Inactivity, disconnecting from the service
2020-04-15 16:18:42.347 27413-28005/com.empodera V/FA: Recording user engagement, ms: 140370
2020-04-15 16:18:42.360 27413-28005/com.empodera V/FA: Connecting to remote service
2020-04-15 16:18:42.409 27413-28005/com.empodera V/FA: Activity paused, time: 860506176
2020-04-15 16:18:42.569 27413-28005/com.empodera V/FA: Connection attempt already in progress
2020-04-15 16:18:42.570 27413-28005/com.empodera D/FA: Connected to remote service
2020-04-15 16:18:42.573 27413-28005/com.empodera V/FA: Processing queued up service tasks: 2
2020-04-15 16:18:44.437 27413-28005/com.empodera D/FA: Application going to the background
2020-04-15 16:18:49.620 27413-28005/com.empodera V/FA: Inactivity, disconnecting from the service
  • logcat you posted doesn’t help much. When crash happens, leave the crash dialog open and go to logcat. In the logcat you will see some red lines that include an Exception. Paste here the complete Exception

  • 1

    Hi Rosario, thank you for the willingness to help me, but I have already solved the problem. The problem was because I needed to migrate my project to Android X. The Solution ta here https://answall.com/questions/448944/problemas-em-instantaner-a-classe-appcomponentfactory-android

1 answer

0


I was able to solve the problem. The problem was because the Androidx class was not being instantiated correctly, so I could call the appCompact class.

I solved the problem by migrating the project to Androidx, as shown in the picture below:

migração do projeto para AndroidX

Browser other questions tagged

You are not signed in. Login or sign up in order to post.