In this class, the List is generated, and should be output to the Log, but this does not happen, although the stream is created
private class LooperThread extends Thread implements Handler.Callback{ Handler handler; @Override public void run() { Looper.prepare(); handler = new Handler(this); Looper.loop(); } @Override public boolean handleMessage(Message message) { if(message.what == 0){ DepositGeneration generation = new DepositGeneration(); DepositOperations operations = new DepositOperations(generation.setList()); List<DepositItem> list = operations.sortedList(); for (int i = 0; i < list.size(); i++) { Log.d("TAG", list.get(i).getName() + " " + new SimpleDateFormat("dd.MM.yyyy").format(list.get(i).getOpenedDate()) + " " + new DecimalFormat("#0.00").format(list.get(i).getAmount())); } } return true; } public Handler getHandler() { return handler; } } And his challenge
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); looperThread = new LooperThread(); looperThread.start(); } At the end destroy the flow
@Override public void onDestroy() { if(looperThread.getHandler() != null){ Log.d("TAG", "DESTROY"); looperThread.getHandler().getLooper().quit(); } super.onDestroy(); } A message in the Log that is destroyed, goes
Changed the call and send the message, but not executed
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); looperThread = new LooperThread(); if (looperThread.getHandler() != null){ Message message = looperThread.getHandler().obtainMessage(0); message.sendToTarget(); } looperThread.start(); }
LooperThread, and not justThread. - woesssrun, andhandleMessagedoes not belong toLooperThreadand is not associated with it. It is called by the handler when the message is received, or rather, when the message is to be processed. - woesssrun, which will work after callinglooperThread.start();and that is not a fact that instantly. And you are addressing it before the start. - woesss