title: Codemane One call Back Command from second Class
body: <p>So, I have an Android App with two classes, A and B. The logic for the back-command is set up in class A and works as expected: the button action shows Form B and the the Escape button brings Form A back.</p>
  
  <p>Now, after loading the form in Class B, I need to "reload" it. I do this by creating a new Form, calling the whole class again, via a button. </p>
  
  <p>In the process, the back-command ceases to work (and the command button to appear in the toolbar), since all the components (toolbar, form, etc.) are newly created, and lack the definitions from Class A. </p>
  
  <p>My question: is it possible to define the back-command logic inside Class B, instead of in Class A, so that the back-command still works after reloading Class B, or somehow define references to Class A to make it work? </p>
  
  <p>Below is the code I already have. Many thanks in advance fro any kind suggestions. </p>
  
  <pre><code>public class ClassA {
  
      private Command back; 
      private ClassB classB;
      private Form current;
      private Resources theme;
      private  Form formA;
      private Button button = new Button("Go forward");
  
      public void loadA() {
  
          showBack();
  
          formA = new Form("Old Form", BoxLayout.y());            
          classB = new ClassB();
  
          button.addActionListener(l -&gt; {
  
              classB = new ClassB();
              classB.formB.getToolbar().setBackCommand(back);
              classB.formB.setBackCommand(back);
  
              classB.goBack();
  
              Button buttonToolbar = classB.formB.getToolbar().findCommandComponent(back);
  
              FontImage image = FontImage.createMaterial(FontImage.MATERIAL_10K, "test", 4);
              buttonToolbar.setIcon(image);
  
  
          });
  
          formA.add(button);
          formA.show();
      }
  
      public void showBack() {
  
          back = new Command("Back") {
                  @Override
                  public void actionPerformed(ActionEvent evt) {
                          formA.showBack();
                  }
          };
      }
  
  }
  
  public class ClassB {
  
      public ClassA classA = new ClassA();
      public Form formB = new Form("New Form", BoxLayout.y());
      private Button buttonReload = new Button("Reload");
  
      public void reload () {
  
          buttonReload.addActionListener(l -&gt; {
  
              ClassB classB = new ClassB();
              classB.reload();
  
              // I want to recreate the back-command logic here in Class B. 
              // The below doesn't work. 
  
              formB.getToolbar().setBackCommand(new Command("back"));
  
          });
  
          formB.add(buttonReload);
          formB.show();
  
      }
  
  }
  </code></pre>