title: Accesing a MainActivity object from another class
body: <p>I have a difficult situation with an android program im writing. So.. :
  I have created a GoogleMap object (theMap) in MainActivity.Then I start a new Activity called GetDirections and it starts a new Class called RequestDirection(Non-Activity).The class RequestDirection performs Google Directions API request and parses the JSON result to create a PolylineOptions object. So HOW can i access the GoogleMap object (theMap) to add the polyline???
  Example code:</p>
  
  <pre><code>public class MainActivity extends Activity {
  public GoogleMap theMap;
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  locationIcon=R.drawable.red_pin;
  
      theMap=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
          }}
  
  public class GetDirections extends Activity{
  //ask user to set Start/Destination Point
  
  RequestDirection req= new RequestDirection();
  req.execute();
  finish();
  }
  
  public class RequestDirection extends AsyncTask {
  
  doInBackground( ){
  //returns the json string
  }
  
  onPostExecute( ){
  PolylineOptions options= (the overview polyline points)
  }
  
  }
  </code></pre>
  
  <p>Note that all 3 classes are NOT nested.they are separate files</p>
  
  <p>I could use mainActivity context and pass it to a new class but now i start a new Activity and i istantiate the class from there.</p>
  
  <p>What can i do?? I wasted a whole day and no solution..</p>
  
  <hr>
  
  <p>Added the exceptions for   dst  suggestion:</p>
  
  <pre><code>08-19 03:13:38.127: W/dalvikvm(1871): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
  08-19 03:13:38.157: E/AndroidRuntime(1871): FATAL EXCEPTION: main
  08-19 03:13:38.157: E/AndroidRuntime(1871): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {com.ceid.CeidMaps/com.ceid.CeidMaps.MainActivity}: java.lang.NullPointerException
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3141)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3184)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at android.app.ActivityThread.access$1100(ActivityThread.java:130)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at android.os.Handler.dispatchMessage(Handler.java:99)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at android.os.Looper.loop(Looper.java:137)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at android.app.ActivityThread.main(ActivityThread.java:4745)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at java.lang.reflect.Method.invokeNative(Native Method)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at java.lang.reflect.Method.invoke(Method.java:511)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at dalvik.system.NativeStart.main(Native Method)
  08-19 03:13:38.157: E/AndroidRuntime(1871): Caused by: java.lang.NullPointerException
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at com.ceid.CeidMaps.MainActivity.onActivityResult(MainActivity.java:162)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at android.app.Activity.dispatchActivityResult(Activity.java:5192)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
  08-19 03:13:38.157: E/AndroidRuntime(1871):     ... 11 more
  </code></pre>