I have tried className.this.finish and finishActivity() to invoke the finishing of my activity and I have initialised the activity with the following methods - startActivityFor
I found the error. insted of:
mDatabase.child("Devices").child(MacCerca).child("Users").addValueEventListener(new ValueEventListener() {
change for:
mDatabase.child("Devices").child(MacCerca).child("Users").addListenerForSingleValueEvent(new ValueEventListener() {