I am extending my class from GLScreen class. But I need to call the Activity class methods such as getString and getPreferences. How can I call these methods? Because I can extend only from one class.
            Asked
            
        
        
            Active
            
        
            Viewed 32 times
        
    1 Answers
1
            
            
        You have to pass a reference of your Activity to your class to able to call getPreferences()/getString(). You can do this via constructor/setter.
Something like this:
public YOURCLASS extends GLScreen {
     Activity mActivity;
     public YOURCLASS(Activity activity){
         mActivity = activity;
     }
     ...
     // call this in a method
     mActivity.getString(...);
}
In your Activity call it like this:
YOURCLASS foo = new YOURCLASS(this);  
 
    
    
        Steve Benett
        
- 12,843
- 7
- 59
- 79
- 
                    When I do I like this I get the exception "can't create handler inside thread that has not called looper.prepare'. I tried these ways: http://stackoverflow.com/questions/3875184/cant-create-handler-inside-thread-that-has-not-called-looper-prepare It gives null pointer exception. Please help – user3634684 May 21 '14 at 23:34
- 
                    @user3634684 Then ask a question with all your details! What you want to achieve and what code you already have. – Steve Benett May 22 '14 at 07:04
