后台开启线程的函数写法:
更加简洁明了:
public class BackTaskRunner { private static final String TAG = "BackTaskRunner"; private HandlerThread handlerThread; private Handler handler; private BackTaskRunner() { handlerThread = new HandlerThread(TAG); handlerThread.start(); handler = new Handler(handlerThread.getLooper()); } public static Handler getHandler() { return SingletonHolder.sRunner.handler; } private static class SingletonHolder { static BackTaskRunner sRunner = new BackTaskRunner(); } }
调用方法:
BackTaskRunner.getHandler().post(new Runnable() { @Override public void run() { Logging.d(TAG, "pay() start UNPay"); //最后一个参数: "01" 代表测试环境 "00" 代表正式环境 UPPayAssistEx.startPay(activity,null,null,tn,payMode); } });
时间: 2024-10-27 10:53:38