title: Include custom Activity inside of Unity Android Plugin (Without overriding UnityPlayerActivity)?
body: <p>I am trying to write an Android Plugin for Unity3D to interface with the Google Play In App Billing. I am aware that there are existing plugins out there for this, but I wish to do it on my own.</p>
  
  <p>It appears that I need to catch Android's Activity::onActivityResult to handle a successful purchase through the GPlay IAB SDK. My issue is that my Java class does not contain an Activity because I want it to run in the background behind the actual Unity application.</p>
  
  <p>This is the code from the GPlay IAB SDK which initiates the Purchase flow. If I pass "UnityPlayer.currentActivity" as the activity, Google Play pops up, and you can successfully purchase the product. However, you do not receive a successful message to the OnIabPurchaseFinishedListener. If the purchases is unsuccessful (ie: you already own the product) then I do receive the callback there.</p>
  
  <pre><code>public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
                          OnIabPurchaseFinishedListener listener, String extraData)
  ...
  ...
  act.startIntentSenderForResult(pendingIntent.getIntentSender(),
                                             requestCode, new Intent(),
                                             Integer.valueOf(0), Integer.valueOf(0),
                                             Integer.valueOf(0));
  </code></pre>
  
  <p>Full Source Here: <a href="http://pastebin.com/xwUbrwTz" rel="noreferrer">http://pastebin.com/xwUbrwTz</a></p>
  
  <p>And here is the section from the Google Play In App Billing SDK's (example code) which posts the successful callback (which I am not receiving)</p>
  
  <pre><code>/**
       * Handles an activity result that's part of the purchase flow in in-app billing. If you
       * are calling {@link #launchPurchaseFlow}, then you must call this method from your
       * Activity's {@link android.app.Activity@onActivityResult} method. This method
       * MUST be called from the UI thread of the Activity.
       *
       * @param requestCode The requestCode as you received it.
       * @param resultCode The resultCode as you received it.
       * @param data The data (Intent) as you received it.
       * @return Returns true if the result was related to a purchase flow and was handled;
       *     false if the result was not related to a purchase, in which case you should
       *     handle it normally.
       */
      public boolean handleActivityResult(int requestCode, int resultCode, Intent data)
  </code></pre>
  
  <p>Full Source: <a href="http://pastebin.com/VTfxJhKx" rel="noreferrer">http://pastebin.com/VTfxJhKx</a></p>
  
  <p>Here is how Google's example code processes the onActivityResult callback:</p>
  
  <pre><code>@Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
  
          // Pass on the activity result to the helper for handling
          if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
              // not handled, so handle it ourselves (here's where you'd
              // perform any handling of activity results not related to in-app
              // billing...
              super.onActivityResult(requestCode, resultCode, data);
          }
          else {
              Log.d(TAG, "onActivityResult handled by IABUtil.");
          }
      }
  </code></pre>
  
  <p>Now, the reason I don't want to override the UnityPlayerActivity class (Search "Extending the UnityPlayerActivity Java Code" on Google, it's the second link. Lack of reputation prevents me from posting the direct link.) is because this requires you to modify the androidmanifest.xml to point to the new "Launcher" - this is a problem because several of the existing Ad platforms for Android already require you to modify the launcher to point to their own Java class. I would like to be able to co-exist with these which prevents me from extending the existing Unity Activity.</p>
  
  <p>I attempted to start my own Activity within my Java class (which is spawned by Unity without issues) but that minimizes the Unity application and pulls up a blank Activity - obviously not what I want.</p>
  
  <p>My question(s):
  Can I extend/catch/hook into the existing UnityAndroidPlayer class and add an onActivityResult function (it doesn't have one by default).</p>
  
  <p>If no, can I make an activity within an Android plugin that doesn't take focus on the phone?</p>
  
  <p>If no, can I modify the code from the Google Play SDK (act.startIntentSenderForResult(..)) to notify me in a different way?</p>
  
  <p>If no, what can I do?</p>