Access Context from another activty in Android -


I have a main category and the other two classes are WebServicesClass and DynamicHeightAdpater names.

I'm making an example in the Websites class, DynamicHight adapter for which I need reference of main activity, but I'm not sure how to indicate it. The way I'm calling it throws a nullioner exception.

Code:

Key Activity:

  Fixed reference context; Context = this.context;  

WebServicesclass:

  New dynamicheet adapter (MainactivityConnect, 1, line items);  

But this is a null pointer throws exception and I'm sure that it is due to the reference reason that I tried to print it and threw it NullPointer.

I suggest you pay attention to this. You can archive references in it and retrieve it, when necessary: ​​

  Test applications increase public application {Private static reference mAppContext; @ Override Public Empty on Create () {Super. Connet (); MAppContext = getApplicationContext (); } / ** * Returns the context of the application is useful for classes for which reference * is required, but it is not inherently one * * @ Return Application Reference * / Public Fixed Reference getAppContext () {Return mAppContext ; }  

Comments