I have a service that removes an object from my webservice
and return the current List. Each time I request the service, it updates my textview
(with the size of the list) and my adapter. The problem is when I go to the MainActivity
and return to the activity which do this service, the textview
and the adapter did not update anymore.
apiServices.deleteEmployee(new APIServices.BookmarkCallback() {
@Override
public void onSuccess(final ArrayList<Employee> list) {
remainingPeople.setText(getResources().getString(R.string.remaining_people) + list.size());
adapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_list_item_1, list);
employeesList.setAdapter(adapter);
}
The code is setted on my onCreate()
method.
The idea is still update the textview
when return to the activity.
onCreate()
method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.activity_count);
remainingPeople = findViewById(R.id.peopleCounter);
findBT();
openBT();
@SuppressWarnings("unchecked")
ArrayList<Employee> list = (ArrayList<Employee>) getIntent()
.getSerializableExtra(SEND_EMPLOYEES_LIST);
remainingPeople.setText(getResources().getString(R.string.remaining_people) + list.size());
employeesList = findViewById(R.id.employees_list);
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, list);
employeesList.setAdapter(adapter);
beep = new ToneGenerator(AudioManager.STREAM_ALARM, 900);
handler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message message) {
switch (message.what) {
case READ_ARRAY_BYTE:
byte[] arrayBytes = new byte[message.arg1];
System.arraycopy(message.obj, 0, arrayBytes, 0, message.arg1);
try {
String epc = new String(arrayBytes, "UTF-8");
beep.stopTone();
epc = epc.substring(0, 24);
apiServices.deleteEmployee(new APIServices.BookmarkCallback() {
@Override
public void onSuccess(final ArrayList<Employee> list) {
//this part updates after the API response
remainingPeople.setText(getResources().getString(R.string.remaining_people) + list.size());
adapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_list_item_1, list);
employeesList.setAdapter(adapter);
}
@Override
public void onError() {
}
}, epc);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
break;
//...