I'm getting the dreaded "the application may be doing too much work on its main thread."
I've read up on background threading, however, I don't know hoe to use it in my existing code.
Please tell me which parts of the code I should post for assistance. Thanks
\below is the HomeActivity.Class that seems to be the problem, once the user logs is the screen just freezes and gives the thread exception\
public void initDrawer() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = findViewById(R.id.drawer_layout_driver);
navigationView = findViewById(R.id.nav_view_driver);
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home_driver, R.id.nav_history_driver, R.id.nav_update_info_driver)
.setOpenableLayout(drawer)
.build();
navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
navigationView.setNavigationItemSelectedListener(this);
}
private void loadUser(){
AsyncTask.execute(() -> FirebaseDatabase.getInstance().getReference(DriversCommon.user_driver_tbl)
.child(DriversCommon.userID)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
DriversCommon.currentUser = dataSnapshot.getValue(DriverUser.class);
onlineRef = FirebaseDatabase.getInstance().getReference().child(".info/connected");
currentUserRef = FirebaseDatabase.getInstance().getReference(DriversCommon.driver_tbl).child("CurrentDriver")
.child(DriversCommon.userID);
onlineRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot1) {
currentUserRef.onDisconnect().removeValue();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}