I am building a task-list management application for Android using Java and Firebase Real-time database. I am currently trying to integrate adding a task to the database and viewing this the task data/name on the application. I pretty much have this however, the code I have created points to one record of a task
e.g. (ref.child("Task 02").setValue(task);
This of course overwrites the task 02 record, I want to be able to increment the task number by '1' every time a task is added to the database. Can somebody please provide some assistance?
I have tried completely different approaches to integrating both interfaces together via YouTube tutorials none of them work as well as the code I currently have now and I have now hit a brick wall. This system is for a final project in Computer Science as part of my dissertation.
database = FirebaseDatabase.getInstance();
ref = database.getReference("Task");
task = new Task();
}
private void getValues() {
task.setDate(dateField.getText().toString());
task.setAssignedTo(spinnerAssign.getSelectedItem().toString());
task.setDescription(description.getText().toString());
task.setName(newTask.getText().toString());
}
public void addTaskBtn (View v) {
Intent intent = new Intent(Add_Task.this , Retrieve_Tasks.class);
startActivity(intent);
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
getValues();
ref.child("Task 02").setValue(task);
Toast.makeText(Add_Task.this, "Task added....", Toast.LENGTH_LONG).show();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
The actual result - Task '02' is overwritten by Firebase database. Expected result - The child ref should increment by one every time a task is added.