【发布时间】:2020-12-07 17:59:52
【问题描述】:
什么是unreachable语句。 我无法使用firebasefirestore 并且method 在片段视图 中是无法访问的语句。 怎么用方法等东西,什么是unreachable语句?
private FragmentPostfragBinding binding;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
binding=FragmentPostfragBinding.inflate(inflater,container,false);
View view=binding.getRoot();
return view;
userview();
}
private void userview() {
FirebaseFirestore db;
db=FirebaseFirestore.getInstance();
DocumentReference ref = db.collection("user").document(FirebaseAuth.getInstance().getCurrentUser().getUid());
ref.get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>(){
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if(documentSnapshot.exists()){
String name=documentSnapshot.getString("username");
binding.user.setText(name);
}
else{
Toast.makeText(getActivity(), "Sorry, your information is not saved!", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(getActivity(),otherinfo.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getActivity(), "Error!", Toast.LENGTH_SHORT).show();
Log.i(TAG, "onFailure: "+e.toString());
}
});
}
}
【问题讨论】:
标签: java android firebase android-fragments android-fragmentactivity