Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need help with android plugin, it crashed my app now

Discussion in 'Android' started by CyberTurboPlays, Mar 14, 2016.

  1. CyberTurboPlays

    CyberTurboPlays

    Joined:
    Nov 7, 2014
    Posts:
    65
    hi
    i m making a android unity plugin for Alipay SDK. but like in the title, it crashed my game/app

    basicly i used nearly all the code from Alipay SDK android Demo for the android java side of code, then you know, i first make a java singleton obj to go with this plugin (you know, no xml page resource file required, just a jar was enough), but its not working(its either not showing my local alipay app on my phone, or the alipay app shown up but shown order info incorrect), then i thought maybe it just didnt like UnityPlayer.currentActivity to make the invokation.

    then, i decided to try a different approach, where i used a intermedia xml page (a new android native activity), to make the invokation to alipay app. again, not working, and its even worse than before, it kept crashing when i press pay.

    i think the problem comes from when the 2ndary thread finished, and used the Handler to call back to the main thread. coz when i removed the Handler bit of code, the crash went away, still, could not invoke the local Alipay app.

    so , i was wondering, is there some limitation on using multithread on android when the app was started with UnityPlayerActivity? coz the pay code from the java was confirmed to be working (when on native app build).

    what can i do to make this work?

    here is the pay code from Java side(the essential part):

    Code (CSharp):
    1.     Runnable payRunnable = new Runnable()
    2.      {
    3.        @Override
    4.        public void run()
    5.        {
    6.          PayTask alipay = new PayTask(TbAliPay_Transit_Page_A_Act.this);
    7.          String result = alipay.pay(payInfo,true);
    8.        
    9.          Message msg = new Message();
    10.          msg.what = SDK_PAY_FLAG;
    11.          msg.obj = result;
    12.          mHandler.sendMessage(msg);
    13.        }
    14.      };
    when i removed :
    Code (CSharp):
    1.          Message msg = new Message();
    2.          msg.what = SDK_PAY_FLAG;
    3.          msg.obj = result;
    4.          mHandler.sendMessage(msg);
    the crash went away. plz help
     
  2. Graybull

    Graybull

    Joined:
    Jul 16, 2013
    Posts:
    2
    Hi there!

    I've actually been working on this same exact thing the past few weeks and have a solution. PM me and I'll go over what you need.
     
  3. Milo_del_mal

    Milo_del_mal

    Joined:
    Jan 27, 2013
    Posts:
    43
    You are a sweetheart. <3