Call MainActivity function outside the class

metalcracker

I try to show the ad outside the MainActivity. If I call showAd in this class it works good and show my ad, but when I call this function in my game class via implemented interface I have an error: "Requires the main thread"

MMRequest request = new MMRequest(); ;  
    MMInterstitial interstitial;
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
        super.onCreate(savedInstanceState);   
        MMSDK.initialize(this);  
        interstitial = new MMInterstitial(this);               
        interstitial.setMMRequest(request);
        interstitial.setApid("xxxxxx");  

        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();    

        RelativeLayout layout = new RelativeLayout(this);

        View gameView = initializeForView(new JumpJackieJump(new RequestHandler(), this), cfg);
        layout.addView(gameView);           

        setContentView(layout);  }

@Override
public void showAd() 
{   
    interstitial.fetch();
    interstitial.setListener(new RequestListenerImpl() 
    {   
        @Override
        public void requestCompleted(MMAd mmAd) 
        {
            interstitial.display();             
        }           
});
Alexander Kohler

This is because the main thread is the UI thread. (Keep in mind this is only for android - For more reference see this).

As per the Android documentation, you should avoid updating the UI outside the UI thread.

Additionally, the Andoid UI toolkit is not thread-safe. So, you must not manipulate your UI from a worker thread—you must do all manipulation to your user interface from the UI thread.

This being said, you may be able to do what you're looking for with something like this.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Call function outside of class from UIButton

From Dev

How to call MainActivity function from the extended BroadcastReceiver class

From Dev

how to properly call a function when it is a pointer to a class function but is outside that class

From Dev

how to properly call a function when it is a pointer to a class function but is outside that class

From Dev

Having a class member function call a function outside the class

From Dev

PHP Call outside class function inside anonymous function

From Dev

call method and Variable in the MainActivity class

From Dev

Call function in fragment from MainActivity

From Dev

How do I call outside function from class in python

From Dev

Angular 2 - Call a function that exists outside of the current class

From Dev

Android: Call and execute a Class on the MainActivity Class

From Dev

Call a function outside main ()

From Dev

Call a function outside main ()

From Dev

popup outside of a function call

From Dev

call var in function to outside the function

From Dev

'super' outside of function or class

From Dev

@staticmethod or function outside class?

From Dev

Run function with class and outside class

From Dev

How to call method outside class

From Dev

How can I call a function that is defined outside of a class from inside a class

From Dev

If a function (that's outside of the class) needs to use a method from a class, how do I call the method?

From Dev

Call a function of a library, outside the library

From Dev

Call This Function Outside of Form Submit

From Dev

Call controller function from outside

From Dev

How to Call PHP function outside

From Dev

is there any way to call an outside class to the main class?

From Dev

Access to WebView from another function in MainActivity class

From Dev

Overriding a function outside its class

From Dev

Error defining function outside the class

Related Related

  1. 1

    Call function outside of class from UIButton

  2. 2

    How to call MainActivity function from the extended BroadcastReceiver class

  3. 3

    how to properly call a function when it is a pointer to a class function but is outside that class

  4. 4

    how to properly call a function when it is a pointer to a class function but is outside that class

  5. 5

    Having a class member function call a function outside the class

  6. 6

    PHP Call outside class function inside anonymous function

  7. 7

    call method and Variable in the MainActivity class

  8. 8

    Call function in fragment from MainActivity

  9. 9

    How do I call outside function from class in python

  10. 10

    Angular 2 - Call a function that exists outside of the current class

  11. 11

    Android: Call and execute a Class on the MainActivity Class

  12. 12

    Call a function outside main ()

  13. 13

    Call a function outside main ()

  14. 14

    popup outside of a function call

  15. 15

    call var in function to outside the function

  16. 16

    'super' outside of function or class

  17. 17

    @staticmethod or function outside class?

  18. 18

    Run function with class and outside class

  19. 19

    How to call method outside class

  20. 20

    How can I call a function that is defined outside of a class from inside a class

  21. 21

    If a function (that's outside of the class) needs to use a method from a class, how do I call the method?

  22. 22

    Call a function of a library, outside the library

  23. 23

    Call This Function Outside of Form Submit

  24. 24

    Call controller function from outside

  25. 25

    How to Call PHP function outside

  26. 26

    is there any way to call an outside class to the main class?

  27. 27

    Access to WebView from another function in MainActivity class

  28. 28

    Overriding a function outside its class

  29. 29

    Error defining function outside the class

HotTag

Archive