auth.getInstance无法正常工作

时间:2017-04-12 09:14:52

标签: android firebase firebase-realtime-database firebase-authentication

我喜欢一个可以更新用户数据的表单,忘记了后面的所有逻辑,我只想在inputText上写一些内容并将其保存在firebase中。问题是我得到一个我不知道原因的错误。我做了很多日志,它从不进入if语句,我检查用户是否存在。

代码

public class UserSettings extends AppCompatActivity {

    FirebaseDatabase database;
    private FirebaseAuth auth;
    EditText usernameTxt;
    EditText ageTxt;
    String userId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_settings);
        usernameTxt = (EditText)findViewById(R.id.username);
        ageTxt = (EditText)findViewById(R.id.age);
        auth = FirebaseAuth.getInstance();
    }

    public void user(View view){
        String username = usernameTxt.getText().toString();
        int age = Integer.parseInt(ageTxt.getText().toString());
        Log.d("task21",auth.getCurrentUser().toString());

        if (auth.getCurrentUser() == null) {
            Log.d("task","fail2");
        }
        else{
            Log.d("task","fail3");
            userId = auth.getCurrentUser().getUid();
        }
        Log.d("task","fail4");


        DatabaseReference myRef = database.getReference();
        myRef.child("Users").child(userId).child("username").setValue(username);
    }
}

栈跟踪

04-12 08:11:30.551 19662-19662/com.android.email E/ActivityThread: Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@1ae9859a that was originally bound here
                                                                   android.app.ServiceConnectionLeaked: Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@1ae9859a that was originally bound here
                                                                       at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1077)
                                                                       at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:971)
                                                                       at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1774)
                                                                       at android.app.ContextImpl.bindService(ContextImpl.java:1757)
                                                                       at android.content.ContextWrapper.bindService(ContextWrapper.java:539)
                                                                       at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:181)
                                                                       at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:224)
                                                                       at com.android.email.service.EmailServiceUtils.isServiceAvailable(EmailServiceUtils.java:160)
                                                                       at com.android.email.provider.AccountReconciler.reconcileAccountsInternal(AccountReconciler.java:171)
                                                                       at com.android.email.provider.AccountReconciler.reconcileAccounts(AccountReconciler.java:115)
                                                                       at com.android.email.service.EmailBroadcastProcessorService.reconcileAndStartServices(EmailBroadcastProcessorService.java:305)
                                                                       at com.android.email.service.EmailBroadcastProcessorService.onBootCompleted(EmailBroadcastProcessorService.java:295)
                                                                       at com.android.email.service.EmailBroadcastProcessorService.onHandleIntent(EmailBroadcastProcessorService.java:130)
                                                                       at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:135)
                                                                       at android.os.HandlerThread.run(HandlerThread.java:61)
04-12 08:11:30.562 19662-19717/com.android.email E/EmailServiceProxy: RuntimeException when trying to unbind from service
                                                                      java.lang.IllegalArgumentException: Service not registered: com.android.emailcommon.service.ServiceProxy$ProxyConnection@1ae9859a
                                                                          at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1029)
                                                                          at android.app.ContextImpl.unbindService(ContextImpl.java:1808)
                                                                          at android.content.ContextWrapper.unbindService(ContextWrapper.java:551)
                                                                          at com.android.emailcommon.service.ServiceProxy$ProxyConnection$1.doInBackground(ServiceProxy.java:124)
                                                                          at com.android.emailcommon.service.ServiceProxy$ProxyConnection$1.doInBackground(ServiceProxy.java:111)
                                                                          at android.os.AsyncTask$2.call(AsyncTask.java:292)
                                                                          at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                          at java.lang.Thread.run(Thread.java:818)04-12 08:11:30.551 19662-19662/com.android.email E/ActivityThread: Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@1ae9859a that was originally bound here
                                                                   android.app.ServiceConnectionLeaked: Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@1ae9859a that was originally bound here
                                                                       at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1077)
                                                                       at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:971)
                                                                       at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1774)
                                                                       at android.app.ContextImpl.bindService(ContextImpl.java:1757)
                                                                       at android.content.ContextWrapper.bindService(ContextWrapper.java:539)
                                                                       at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:181)
                                                                       at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:224)
                                                                       at com.android.email.service.EmailServiceUtils.isServiceAvailable(EmailServiceUtils.java:160)
                                                                       at com.android.email.provider.AccountReconciler.reconcileAccountsInternal(AccountReconciler.java:171)
                                                                       at com.android.email.provider.AccountReconciler.reconcileAccounts(AccountReconciler.java:115)
                                                                       at com.android.email.service.EmailBroadcastProcessorService.reconcileAndStartServices(EmailBroadcastProcessorService.java:305)
                                                                       at com.android.email.service.EmailBroadcastProcessorService.onBootCompleted(EmailBroadcastProcessorService.java:295)
                                                                       at com.android.email.service.EmailBroadcastProcessorService.onHandleIntent(EmailBroadcastProcessorService.java:130)
                                                                       at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:135)
                                                                       at android.os.HandlerThread.run(HandlerThread.java:61)
04-12 08:11:30.562 19662-19717/com.android.email E/EmailServiceProxy: RuntimeException when trying to unbind from service
                                                                      java.lang.IllegalArgumentException: Service not registered: com.android.emailcommon.service.ServiceProxy$ProxyConnection@1ae9859a
                                                                          at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1029)
                                                                          at android.app.ContextImpl.unbindService(ContextImpl.java:1808)
                                                                          at android.content.ContextWrapper.unbindService(ContextWrapper.java:551)
                                                                          at com.android.emailcommon.service.ServiceProxy$ProxyConnection$1.doInBackground(ServiceProxy.java:124)
                                                                          at com.android.emailcommon.service.ServiceProxy$ProxyConnection$1.doInBackground(ServiceProxy.java:111)
                                                                          at android.os.AsyncTask$2.call(AsyncTask.java:292)
                                                                          at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                          at java.lang.Thread.run(Thread.java:818)

1 个答案:

答案 0 :(得分:0)

首先,我认为这个错误不属于您自己的应用程序,您的某些电子邮件服务已泄露。 其次,这应该是这样的,所以它想要运行异常:

else{
  Log.d("task","fail3");
  userId = auth.getCurrentUser().getUid();
  DatabaseReference myRef = database.getReference();
  myRef.child("Users").child(userId).child("username").setValue(username).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()){
                Log.d(TAG, "onComplete: DONE");
            }
        }
    });;
 }