请检查注销方法。 当我尝试注销进度条时没有显示。但是应用程序没有崩溃并且工作正常。
完美地移动到下一个活动。
我还尝试通过提供Thread.sleep(2000)
检查进度条但仍然无法正常工作。
这是我附加的HomePage类代码
public class HomePage extends AppCompatActivity {
private FirebaseAuth mAuth;
DatabaseReference mData;
TextView t;
ProgressBar progressBar;
public void logout(View v) throws InterruptedException {
progressBar.setVisibility(View.VISIBLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
FirebaseAuth.getInstance().signOut();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
progressBar.setVisibility(View.GONE);
Intent i = new Intent(HomePage.this,MainActivity.class);
startActivity(i);
}
public void profile(View v){
Intent i = new Intent(HomePage.this,ProfilePage.class);
startActivity(i);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
mAuth = FirebaseAuth.getInstance();
RelativeLayout layout = findViewById(R.id.layout);
progressBar = new ProgressBar(HomePage.this,null,android.R.attr.progressBarStyleLarge);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(progressBar,params);
progressBar.setVisibility(View.INVISIBLE);
mData = FirebaseDatabase.getInstance().getReference();
// final String[] name = new String[1];
t = (TextView) findViewById(R.id.loginName);
final String uid = mAuth.getUid();
mData.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
progressBar.setVisibility(View.VISIBLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
showData(dataSnapshot,uid);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getApplicationContext(),"Check your Connection",Toast.LENGTH_SHORT);
}
});
}
private void showData(DataSnapshot dataSnapshot,String uid) {
User u = new User();
for(DataSnapshot ds : dataSnapshot.getChildren()) {
u.setName(ds.child(uid).getValue(User.class).getName());
}
t.setText(u.getName());
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
progressBar.setVisibility(View.GONE);
}
}
主页活动的Xml代码
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ashwanths.helpwithfood.HomePage">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:paddingBottom="20sp"
android:paddingEnd="20sp"
android:paddingLeft="20sp"
android:paddingRight="20sp"
android:paddingStart="20sp"
android:paddingTop="20sp"
android:text="Welcome "
android:textSize="20sp" />
<TextView
android:id="@+id/loginName"
android:layout_width="255dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:gravity="left"
android:padding="20sp"
android:text=""
android:textSize="20sp" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/loginName"
android:layout_centerHorizontal="true"
android:layout_marginTop="89dp"
android:onClick="profile"
android:text="Profile Page" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:text="Add a person" />
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="14dp"
android:onClick="logout"
android:text="SignOut" />
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/button3"
android:text="Give Food" />
</android.widget.RelativeLayout>
即使在OnDataChange()
中,进度条也没有显示请帮帮我。