gpt4 book ai didi

java - 如何修复 'handleWindowVisibility: no activity for token android.os.BinderProxy' ?

转载 作者:太空狗 更新时间:2023-10-29 13:44:54 30 4
gpt4 key购买 nike

我正在开发一个小型应用程序,该应用程序已经过测试并且一直运行良好。当我添加新代码让应用程序将信息发送到我的 Firebase 实时数据库时,它只是不会启动我的应用程序。它会使 MainActivity 闪烁一秒钟然后变黑。

当我删除输入的代码时,enter code here 会继续执行相同的操作。尽管相同的代码(在删除我认为不好的代码之后)之前可以正常工作。我翻遍了论坛,但在 Activity 完成之前没有找到任何引用对话框的代码

,,,
/com.fromfire.fantastysurvivor W/ActivityThread: handleWindowVisibility:
no activity for token android.os.BinderProxy@356e9f5
2019-05-08 07:46:47.891 3306-3306/com.fromfire.fantastysurvivor V/FA:
onActivityCreated
2019-05-08 07:46:47.998 3306-3306/com.fromfire.fantastysurvivor
W/ActivityThread: handleWindowVisibility: no activity for token
android.os.BinderProxy@c10e219
2019-05-08 07:46:48.014 3306-3306/com.fromfire.fantastysurvivor V/FA:
onActivityCreated
2019-05-08 07:46:48.108 3306-3306/com.fromfire.fantastysurvivor
W/ActivityThread: handleWindowVisibility: no activity for token
android.os.BinderProxy@2818389
2019-05-08 07:46:48.116 3306-3306/com.fromfire.fantastysurvivor V/FA:
onActivityCreated
2019-05-08 07:46:48.238 3306-3306/com.fromfire.fantastysurvivor
W/ActivityThread: handleWindowVisibility: no activity for token
android.os.BinderProxy@b4e046d
2019-05-08 07:46:48.254 3306-3306/com.fromfire.fantastysurvivor V/FA:
onActivityCreated
2019-05-08 07:46:48.359 3306-3306/com.fromfire.fantastysurvivor
W/ActivityThread: handleWindowVisibility: no activity for token
android.os.BinderProxy@685e2dd
2019-05-08 07:46:48.383 3306-3306/com.fromfire.fantastysurvivor V/FA:
onActivityCreated
,,,

,,,java
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import java.util.HashMap;

import de.hdodenhof.circleimageview.CircleImageView;

public class SetupActivity extends AppCompatActivity
{

private EditText UserName, FullName, CountryName;
private Button SaveInformationButton;
private CircleImageView ProfileImage;
private FirebaseAuth mAuth;
private DatabaseReference UsersRef;
private ProgressDialog loadingBar;

String currentUserID;


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

mAuth = FirebaseAuth.getInstance();
currentUserID = mAuth.getCurrentUser().getUid();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);

UserName = (EditText) findViewById(R.id.setup_username);
FullName = (EditText) findViewById(R.id.set_full_name);
CountryName = (EditText) findViewById(R.id.setup_country_name);
SaveInformationButton = (Button) findViewById(R.id.setup_information_button);
ProfileImage = (CircleImageView) findViewById(R.id.setup_profile_image);
loadingBar = new ProgressDialog(this);

SaveInformationButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
SaveAccountSetupInformation();
}
});

}

private void SaveAccountSetupInformation()
{
String username = UserName.getText().toString();
String fullname = FullName.getText().toString();
String country = CountryName.getText().toString();

if(TextUtils.isEmpty(username))
{
Toast.makeText(SetupActivity.this, "Please enter Username", Toast.LENGTH_SHORT).show();
}
if(TextUtils.isEmpty(fullname))
{
Toast.makeText(SetupActivity.this, "Please enter your full name", Toast.LENGTH_SHORT).show();
}
if(TextUtils.isEmpty(country))
{
Toast.makeText(SetupActivity.this, "Please enter you country", Toast.LENGTH_SHORT).show();
}
else
{

loadingBar.setTitle("Saving information...");
loadingBar.setMessage("Please wait...");
loadingBar.show();
loadingBar.setCanceledOnTouchOutside(true);

HashMap userMap = new HashMap();
userMap.put("username", username);
userMap.put("fullname", fullname);
userMap.put("country", country);
userMap.put("status", "Hey There");
UsersRef.updateChildren(userMap).addOnCompleteListener(new OnCompleteListener()
{
@Override
public void onComplete(@NonNull Task task)
{
if(task.isSuccessful())
{
SendUserToMainActivity();
Toast.makeText(SetupActivity.this, "Account created successfully", Toast.LENGTH_LONG).show();
loadingBar.dismiss();
}
else
{
String message = task.getException().getMessage();
Toast.makeText(SetupActivity.this, "Error occured: " + message, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}

private void SendUserToMainActivity()
{
Intent mainIntent = new Intent(SetupActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);

}
}
,,,
Build Gradle (App)
,,,
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.fromfire.fantastysurvivor"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-storage:16.0.4'
implementation 'com.google.firebase:firebase-database:16.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
implementation 'de.hdodenhof:circleimageview:3.0.0'
}
apply plugin: 'com.google.gms.google-services'
,,,

MainActivity
,,,java
package com.fromfire.fantastysurvivor;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.support.v4.view.GravityCompat;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.MenuItem;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.IdpResponse;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

private FirebaseAuth mAuth;
private DatabaseReference UsersRef;

String currentUserID;


List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build());

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

mAuth = FirebaseAuth.getInstance();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");

//Navigation Drawer
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Home");
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);
}

@Override
protected void onStart()
{
super.onStart();

FirebaseUser currentUser = mAuth.getCurrentUser();

if(currentUser == null)
{
SendUserToLoginActivity();
}
else
{
CheckUserExistence();
}
}

private void CheckUserExistence()
{
final String current_user_id = mAuth.getCurrentUser().getUid();

UsersRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
if(!dataSnapshot.hasChild(current_user_id))
{
SendUserToSetupActivity();
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}

private void SendUserToSetupActivity()
{
Intent setupIntent = new Intent(MainActivity.this, SetupActivity.class);
setupIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(setupIntent);
finish();
}

private void SendUserToLoginActivity()
{
Intent loginIntent = new Intent(MainActivity.this, LoginActivity.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(loginIntent);
finish();
}

public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
Fragment fragment;

if (id == R.id.nav_leader) {


} else if (id == R.id.nav_mypicks) {


} else if (id == R.id.nav_tribe) {


} else if (id == R.id.nav_results) {


} else if (id == R.id.nav_chat) {


} else if (id == R.id.nav_settings) {


} else if (id == R.id.nav_about) {


} else if (id == R.id.nav_donate) {


} else if (id == R.id.nav_logout) {
mAuth.signOut();
SendUserToLoginActivity();

} else if (id == R.id.nav_feedback) {


} else if (id == R.id.nav_profile) {


} else if (id == R.id.nav_home) {

}

DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}


}
,,,

我希望在我与用户一起登录后,让该 uID 引用我的 firebase 数据库,如果没有用户具有该 uID,它将把他们重定向到 SetupActivity 类以获取更多信息输入。

现在屏幕闪烁一瞬间(我猜是在显示我的 MainActivity)然后变黑。

最佳答案

我保存了我所有的代码和 xml 并将其直接粘贴到一个新项目中,问题就消失了。一定是遇到了一些非常隐蔽的错误。

关于java - 如何修复 'handleWindowVisibility: no activity for token android.os.BinderProxy' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56042692/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com