2017-04-05 31 views
0

我正在使用Google Firebase創建應用程序,並且我使用了他們提供給您的一些代碼,但我不知道這些變量中有幾個是什麼。變量是「auth_failed」和「EmailPasswordActivity」。這些變量應該是什麼? Firebase身份驗證使用電子郵件創建新帳戶

mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() 
    { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) 
       { 
        Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful()); 

        // If sign in fails, display a message to the user. If sign in succeeds 
        // the auth state listener will be notified and logic to handle the 
        // signed in user can be handled in the listener. 
        if (!task.isSuccessful()) 
        { 
         Toast.makeText(EmailPasswordActivity.this, R.string.auth_failed, Toast.LENGTH_SHORT).show(); 
        } 
       } 
    }); 

回答

0

我建議你看看[文檔Toast.makeText()https://developer.android.com/reference/android/widget/Toast.html#makeText(android.content.Context,INT,INT)),因爲這些變量傳遞到該方法的第一個和第二個參數。

第一個參數被記錄爲:

Context:要使用的上下文。通常你的ApplicationActivity對象。

所以在這種情況下,它EmailPasswordActivity.this指的是代碼是在活動。在此背景下,.this後綴見What is different between MainActivity.this vs getApplicationContext()

第二個參數記錄爲:

resId int:字符串資源的資源ID使用。可以是格式化文本。

所以這是一個字符串資源(在您的應用程序的strings.xml文件中),其中包含要顯示的文本。

順便說一句:code snippet in the documentation鏈接到complete example on Github

+0

我很困惑什麼是上下文或如何使用/創建一個。 –

+0

Android使用它來限制(本例中)Toast的生命週期。這不是Firebase特有的,所以我會在Android文檔中詳細閱讀一些關於它的文章,以獲得不融合和/或http://stackoverflow.com/questions/3572463/what-is-context-on-android。 –

相關問題