How can i keep status 'online' in android

前端 未结 3 1658
我在风中等你
我在风中等你 2020-12-22 01:17

Now i\'m trying to make like a instagram chat program using firebase the problem is i want to show that member login status but android life cycle is problem

Here

3条回答
  •  独厮守ぢ
    2020-12-22 01:49

    Whenever user is in your app, technically he is online. So in your home activity use this:

      @Override
        protected void onStart() {
            super.onStart();
            myRef.child(uid).child("isOnline").setValue(true);
            myRef.child(uid).child("isOnline").onDisconnect().setValue(false);
        }
    

    and also i would suggest to add to override onResume():

        @Override
        protected void onResume() {
            super.onResume();
                myRef.child(uid).child("isOnline").setValue(true); //User back online
    
            }
    

    Make sure to add an if statement to check if user is connected to internet or not!

提交回复
热议问题