Im making Android app with Android Studio. This code is to send data from the app to firebase realtime database. At first, it was an error about window leaked on the dialog.show(). But I updated the code with dialog.dismiss(). But now, the data still not shows on realtime database and the logcat seems fine. This is the class that send the data:
public class KeranjangActivity extends AppCompatActivity {
ListView listView;
public TextView txtTotalHarga;
ArrayList<Keranjang> keranjangArrayList = new ArrayList<>();
KeranjangAdapter adapter = null;
SQLiteHelper helper;
FirebaseDatabase database;
DatabaseReference requests;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_keranjang);
database = FirebaseDatabase.getInstance();
requests = database.getReference("Laundry");
Button btnPesan = findViewById(R.id.btnPesan);
listView = (ListView) findViewById(R.id.listView);
txtTotalHarga = findViewById(R.id.txtTotal);
int total = 0;
String totalHarga = null;
keranjangArrayList = new ArrayList<>();
adapter = new KeranjangAdapter(this, R.layout.list_item, keranjangArrayList);
listView.setAdapter(adapter);
helper = new SQLiteHelper(this, "laundryDB.sqlite", null, 1);
Cursor cursor = helper.getData("SELECT Id, name, quantity, harga FROM CART");
keranjangArrayList.clear();
if (cursor.moveToFirst()) {
do {
int id = cursor.getInt(0);
String namaJenis = cursor.getString(1);
String quantity = cursor.getString(2);
String harga = cursor.getString(3);
Log.e("namaJenis: ", namaJenis);
Log.e("quantity: ", quantity);
Log.e("harga: ", harga);
total = total + Integer.parseInt(harga);
Log.e("totalharga: ", String.valueOf(total));
keranjangArrayList.add(new Keranjang(namaJenis, quantity, id, harga));
} while (cursor.moveToNext());
}
txtTotalHarga.setText(String.valueOf(total));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
AlertDialog.Builder builder = new AlertDialog.Builder(KeranjangActivity.this);
final int pos = position;
builder.setTitle("Dialog Hapus")
.setMessage("Apakah anda ingin menghapus item ini ?")
.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Log.e("CART ID =", keranjangArrayList.get(pos).toString());
Keranjang cart = keranjangArrayList.get(pos);
helper.deleteData(cart.getId());
keranjangArrayList.remove(pos);
adapter.notifyDataSetChanged();
listView.invalidateViews();
}
})
.setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
builder.create();
builder.show();
}
});
btnPesan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (keranjangArrayList.size() > 0) {
submitOrder();
} else {
Toast.makeText(KeranjangActivity.this, "Keranjang Belanja Kosong", Toast.LENGTH_SHORT).show();
}
}
});
listView.setFocusable(true);
adapter.notifyDataSetChanged();
}
private void submitOrder() {
AlertDialog.Builder mBuilder = new AlertDialog.Builder(KeranjangActivity.this);
View mView = getLayoutInflater().inflate(R.layout.activity_dialog_order, null);
final EditText edtNamaPemesan = mView.findViewById(R.id.edt_nama_pemesan);
final EditText edtTglMasuk = mView.findViewById(R.id.tgl_masuk);
final EditText edtTglKeluar = mView.findViewById(R.id.tgl_selesai);
final EditText edtNamaPenerima = mView.findViewById(R.id.edt_nama_penerima);
final Button btnSubmitOrder = mView.findViewById(R.id.finishOrder);
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
dialog.show();
edtTglMasuk.setInputType(InputType.TYPE_NULL);
edtTglMasuk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDateTimeDialog1(edtTglMasuk);
}
});
edtTglKeluar.setInputType(InputType.TYPE_NULL);
edtTglKeluar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDateTimeDialog2(edtTglKeluar);
}
});
btnSubmitOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Request request = new Request(
edtNamaPemesan.getText().toString().trim(),
edtTglMasuk.getText().toString().trim(),
edtTglKeluar.getText().toString().trim(),
edtNamaPenerima.getText().toString().trim(),
txtTotalHarga.getText().toString(),
keranjangArrayList);
requests.child((String.valueOf(System.currentTimeMillis()))).setValue(request);
helper.deleteAllData();
keranjangArrayList.clear();
adapter.notifyDataSetChanged();
listView.invalidateViews();
Toast.makeText(KeranjangActivity.this,"Order laundry telah ditambah",Toast.LENGTH_SHORT).show();
finish();
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
}
});
}
private void showDateTimeDialog1(final EditText edtTglMasuk) {
final Calendar calendar = Calendar.getInstance();
DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
edtTglMasuk.setText(simpleDateFormat.format(calendar.getTime()));
}
};
new DatePickerDialog(KeranjangActivity.this, dateSetListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show();
}
private void showDateTimeDialog2(final EditText edtTglKeluar) {
final Calendar calendar = Calendar.getInstance();
DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
edtTglKeluar.setText(simpleDateFormat.format(calendar.getTime()));
}
};
new DatePickerDialog(KeranjangActivity.this, dateSetListener, calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show();
}
}
And this is the logcat after I clicked submit button:
07-10 23:30:21.751 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.751 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.751 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.761 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.761 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.761 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.761 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.761 31994-31994/com.example.laundryrewang D/AbsListView: Get MotionRecognitionManager
07-10 23:30:21.771 31994-31994/com.example.laundryrewang D/AbsListView: Get MotionRecognitionManager
07-10 23:30:21.781 31994-31994/com.example.laundryrewang D/PhoneWindow: *FMB* installDecor mIsFloating : true
07-10 23:30:21.781 31994-31994/com.example.laundryrewang D/PhoneWindow: *FMB* installDecor flags : 8388610
07-10 23:30:21.791 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.801 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.811 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.821 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:21.831 31994-31994/com.example.laundryrewang D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
07-10 23:30:21.831 31994-31994/com.example.laundryrewang D/PhoneWindow: *FMB* isFloatingMenuEnabled return false
07-10 23:30:22.922 31994-31994/com.example.laundryrewang D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
07-10 23:30:23.342 31994-31994/com.example.laundryrewang D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
07-10 23:30:23.402 31994-31994/com.example.laundryrewang D/InputMethodManager: windowDismissed mLockisused = false
07-10 23:30:23.422 31994-31994/com.example.laundryrewang E/ViewRootImpl: sendUserActionEvent() mView == null
07-10 23:30:24.603 31994-31994/com.example.laundryrewang D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
07-10 23:30:26.115 31994-31994/com.example.laundryrewang D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
07-10 23:30:26.165 31994-31994/com.example.laundryrewang D/TextView: setTypeface with style : 0
07-10 23:30:26.185 31994-31994/com.example.laundryrewang D/InputMethodManager: windowDismissed mLockisused = false
07-10 23:30:26.225 31994-32660/com.example.laundryrewang V/FA: Recording user engagement, ms: 10701
07-10 23:30:26.225 31994-32660/com.example.laundryrewang V/FA: Connecting to remote service
07-10 23:30:26.235 31994-31994/com.example.laundryrewang E/ViewRootImpl: sendUserActionEvent() mView == null
07-10 23:30:26.245 31994-32660/com.example.laundryrewang V/FA: Activity paused, time: 183517649
07-10 23:30:26.295 31994-32660/com.example.laundryrewang V/FA: Connection attempt already in progress
07-10 23:30:26.295 31994-32660/com.example.laundryrewang V/FA: Activity resumed, time: 183517690
07-10 23:30:26.325 31994-32660/com.example.laundryrewang V/FA: Connection attempt already in progress
07-10 23:30:26.325 31994-32660/com.example.laundryrewang V/FA: Connection attempt already in progress
07-10 23:30:26.355 31994-32660/com.example.laundryrewang D/FA: Connected to remote service
07-10 23:30:26.365 31994-32660/com.example.laundryrewang V/FA: Processing queued up service tasks: 4
07-10 23:30:26.385 31994-31994/com.example.laundryrewang I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@146c792e time:84182599
07-10 23:30:26.505 31994-31994/com.example.laundryrewang D/InputMethodManager: windowDismissed mLockisused = false
07-10 23:30:28.177 31994-31994/com.example.laundryrewang D/InputMethodManager: windowDismissed mLockisused = false
Any help is appreciated. Thankyou
Oh, and also I've tried to login and logout the browser, changed web browser, disabled addblocks, enabled token service API but still now working.