How to call and pass other mainscreen?

100 Views Asked by At

In class a which extends MainScreen, I want to call b class which extends MainScreen also.

When I pass b.this into a function error shown No enclosing instance of the type b is accessible in

2

There are 2 best solutions below

1
On BEST ANSWER

Hi this is Very simple I will tell you simple way

Suppose you have two classes

1)screen1

2)screen2

screen1.java

public class screen1 extends MainScreen
{
   // some lines of code 
   //this is method to going to next screen in side that method 
   UiApplication.getUiApplication().pushScreen(new screen2(screen1.this));
}

screen2.java

public class screen2 extends MainScreen
{
   private Screen1 screen1Object;
   // here take constructer
   public screen2(Screen1 screen1Object)
   {
      this.screen1Object=screen1Object;
   }
}

Here you can use that screen1Object

0
On

you can using this code

UiApplication.getUiApplication().invokeAndWait(new Runnable() 
{   
    public void run() 
    {
        UiApplication.getUiApplication().pushScreen(new NewScreen());
    }
});