使用firebase登录内部后,HomeActivity.java甚至没有烘烤。是什么原因造成的。我在Android Oreo虚拟电话上使用Android SDK 5.0
// Verify that the user passed a hostname.
if (hostname!=NULL)
{
// Convert argv[] to a wchar_t*
size_t origsize = strlen(argv[1]) + 1;
size_t convertedChars = 0;
wchar_t wcstring[newsize];
mbstowcs_s(convertedChars, wcstring, origsize, argv[1], _TRUNCATE);
wcscat_s(wcstring, L" (wchar_t *)");
hostName = wcstring;
}
else
{
hostName = NULL;
}
// Initialize a session. LDAP_PORT is the default port, 389.
pLdapConnection = ldap_init(hostName, LDAP_PORT);
if (pLdapConnection == NULL)
{
// Set the HRESULT based on the Windows error code.
char hr = HRESULT_FROM_WIN32(GetLastError());
printf( "ldap_init failed with 0x%x.\n",hr);
goto error_exit;
}
else
printf("ldap_init succeeded \n");
// Set the version to 3.0 (default is 2.0).
returnCode = ldap_set_option(pLdapConnection,
LDAP_OPT_PROTOCOL_VERSION,
(void*)&version);
if(returnCode == LDAP_SUCCESS)
printf("ldap_set_option succeeded - version set to 3\n");
else
{
printf("SetOption Error:%0X\n", returnCode);
goto error_exit;
}
// Connect to the server.
connectSuccess = ldap_connect(pLdapConnection, NULL);
if(connectSuccess == LDAP_SUCCESS)
printf("ldap_connect succeeded \n");
else
{
printf("ldap_connect failed with 0x%x.\n",connectSuccess);
goto error_exit;
}
// Bind with current credentials (login credentials). Be
// aware that the password itself is never sent over the
// network, and encryption is not used.
printf("Binding ...\n");
returnCode = ldap_bind_s(pLdapConnection, NULL, NULL,
LDAP_AUTH_NEGOTIATE);
if (returnCode == LDAP_SUCCESS)
printf("The bind was successful");
else
goto error_exit;
// Normal cleanup and exit.
ldap_unbind(pLdapConnection);
return 0;
// On error cleanup and exit.
error_exit:
ldap_unbind(pLdapConnection);
return -1;
下面的activity_home.xml是以上代码的XML
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class HomeActivity extends AppCompatActivity {
Button bt_logout;
private FirebaseAuth mAuth;
private FirebaseUser user;
@Override
protected void onStart() {
super.onStart();
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
bt_logout = (Button)findViewById(R.id.button_logout);
bt_logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(HomeActivity.this, user + " has Logged out", Toast.LENGTH_LONG).show();
//mAuth.signOut();
//setContentView(R.layout.activity_main);
}
});
}
}
有1个TextView,1个EditView和1个按钮
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".HomeActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello you have logged in"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/txt_welcome"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Logout"
android:id="@+id/button_logout"
android:layout_below="@+id/txt_welcome"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
上面是我没有红色错误的流浪猫
答案 0 :(得分:0)
我终于通过在检查用户会话时从登录活动中删除setContentView
方法来使它起作用。
更新后的代码是-
FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
if(user != null){
//setContentView(R.layout.activity_home); // removed this
}