2

What is this error, and why does it happen?

E/WindowManager: android.view.WindowLeaked: Activity com.example.houseoffashion.MainActivity has leaked window DecorView@b273f3b[Already logged in] that was originally added here
    at android.view.ViewRootImpl.<init>(ViewRootImpl.java:583)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:363)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:128)
    at android.app.Dialog.show(Dialog.java:454)
    at com.example.houseoffashion.MainActivity.onCreate(MainActivity.java:69)
    at android.app.Activity.performCreate(Activity.java:7383)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3256)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3411)
    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5477)
    at android.app.ActivityThread.-wrap19(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2000)
    at android.os.Handler.dispatchMessage(Handler.java:108)
    at android.os.Looper.loop(Looper.java:166)
    at android.app.ActivityThread.main(ActivityThread.java:7529)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

I face this problem in two android projects. In one I was trying to retrieve data from Firebase into Recyclerview and in another, I was trying to login using phone number but in both cases, logcat is showing: it does not display the home page. it just buffering on a login page tell me what happened and how can i solve that problem in accurate way. The code is that...

package com.example.houseoffashion;
//import library
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.example.houseoffashion.Model.Users;
import com.example.houseoffashion.Prevalent.Prevalent;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import io.paperdb.Paper;

public class MainActivity extends AppCompatActivity {


private ProgressDialog LoadingBar;
private String parentDbName = "Users";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //login Button
    Button joinnowbutton = (Button) findViewById(R.id.btn2);
    Button loginbutton = (Button) findViewById(R.id.btn1);
    LoadingBar = new ProgressDialog(this);

    Paper.init(this);
    //when on click a login button
    loginbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, LoginActivity.class);
            startActivity(intent);
        }
    });

    //userid amd userpassword
    String userPhoneKey = Paper.book().read(Prevalent.userPhoneKey);
    String userPasswordKey = Paper.book().read(Prevalent.userPasswordKey);
    //get id and password for login
    if (userPhoneKey != "" && userPasswordKey != "")
    {
        if (!TextUtils.isEmpty(userPhoneKey) && !TextUtils.isEmpty(userPasswordKey))
        {
            AllowAccess(userPhoneKey, userPasswordKey);
   //progress dialogbar
            LoadingBar.setTitle("Already logged in");
            LoadingBar.setMessage("Please wait ........");
            LoadingBar.setCanceledOnTouchOutside(false);
            LoadingBar.show();
        }
    }

}

private void AllowAccess(final String phone_number, final String password)
{
    final DatabaseReference RootRef;
    RootRef = FirebaseDatabase.getInstance().getReference();
 //store data in firebase realtime data
    RootRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot)
        {
            if(dataSnapshot.child(parentDbName).child(phone_number).exists())
            {
                Users usersData = dataSnapshot.child(parentDbName).child(phone_number).getValue(Users.class);

                if (usersData.getPhone_number().equals(phone_number))
                {
                    if (usersData.getPassword().equals(password))
                    {
                        //display a msg already logged in
                        Toast.makeText(MainActivity.this, "Please Wait! You have already logged in...", Toast.LENGTH_SHORT).show();
                        LoadingBar.dismiss();
                        Intent intent = new Intent(MainActivity.this, HomeActivity.class);
                        Prevalent.currentOnlineUser = usersData;
                        startActivity(intent);
                    }
                    else
                    {
                        //dismiss a bar and set a msg incorrect password
                        LoadingBar.dismiss();
                        Toast.makeText(MainActivity.this, "incorrect password...", Toast.LENGTH_SHORT).show();
                    }
                }
            }
            else
            {
                //after successfully login go to the home activity
                Toast.makeText(MainActivity.this, "Account with this" + phone_number + "number do not exists.", Toast.LENGTH_SHORT).show();
                LoadingBar.dismiss();
            }
        }
}
}
Kasım Özdemir
  • 5,414
  • 3
  • 18
  • 35

1 Answers1

1

Possible duplicate of Activity has leaked window that was originally added

You should give a look to that question. It is very useful.

gcantoni
  • 727
  • 6
  • 13