Please check the logout method. When I try to log out progress bar is not showing.But the app does not crash and it works fine .
It moves to the next Activity perfectly.
I also tried to check the progress bar by giving a Thread.sleep(2000)
But still it is not working.
This the HomePage class code that I am attaching
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);
}
}
The Xml code for homepage activity
<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>
Even in OnDataChange()
the progress bar is not showing Please help me.