当前位置: 首页 > 知识库问答 >
问题:

使用应用计费时,信息没有从后台传递到后台执行

方鸿羲
2023-03-14

当我的应用程序启动时,我会启动一个异步任务,以便立即显示用户高级功能。但我没有得到从doInBackground(查询后的值)传递到onPostExecute的信息。

我做了一个查询InventoryAsync,它定义了值是真还是假,然后我在这个值上将此值用于不同的操作。

public class LoadAppBilling extends AsyncTask <Result, Result, Result> {

    static final String SKU_PREMIUMV = "test.hsdbgjfasbdfughvakcshfgb";
    static final String SKU_NO_ADDS = "test.blah";
    static final String TAG = "Azores Bus Premium";
    IabHelper mHelper;
    boolean mPremiumV = false;
    boolean mAdds = false;

    IabHelper.QueryInventoryFinishedListener mGotInventoryListener
            = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result,
                                             Inventory inventory) {

            if (result.isFailure()) {
                Log.d(TAG, "didnt load");
                return;
            }
            Log.d(TAG, " load");

            if (inventory.hasPurchase(SKU_PREMIUMV)) {
                         mPremiumV = true;
                return;
            }
            if (inventory.hasPurchase(SKU_NO_ADDS)) {
                         mAdds = true;
            }

        }
    };

    @Override
    public Result doInBackground(Result... params) {

        String base64EncodedPublicKey = "";

        Log.d(TAG, "Creating IAB helper.");
        mHelper = new IabHelper(getApplication(), base64EncodedPublicKey);

        mHelper.enableDebugLogging(true);

        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (!result.isSuccess()) {
                    // Oh noes, there was a problem.
                    Log.d(TAG, "Problem setting up In-app Billing: " + result);
                }
                // Hooray, IAB is fully set up!
                mHelper.queryInventoryAsync(mGotInventoryListener);
            }
        });


        return null;
    }

    @Override
    public void onPostExecute(Result  result) {

    }

}

然后在片段中,我调用

new LoadAppBilling() {
         @Override
     public void onPostExecute (Result result) {
     super.onPostExecute(result);

if (mPremiumV) {
//open a fragment 

} else {    
// show a dialog
    }}
}
.execute();
break;

共有2个答案

都建树
2023-03-14

像一些用户的评论一样,从<code>doInBackground()。

根据您的代码,您的方法doInbackground()必须返回“Result”类型的值

@Override
    public Result doInBackground(Result... params) {

        Result res;
...
...
...

        return res;
    }
宋智明
2023-03-14

起初我很难理解你在这里想做什么,但我认为这可能会有所帮助:

快速查看更改:

 public class LoadAppBilling extends AsyncTask <Result, Result, ArrayList<Boolean>> 

.......

 ArrayList<Boolean> retVal = new ArrayList<Boolean>();
                retVal.add(mPremiumV);
                retVal.add(mAdds);

                return retVal;

.......

 @Override
    public void onPostExecute(ArrayList<Boolean>  result) {

片段:

public void onPostExecute (ArrayList<Boolean> result) {
         super.onPostExecute(result);

         //This will auto-unbox to boolean primitive
         boolean mPremiumV = result.get(0);
         boolean mAdds = result.get(1);

把它们都放在一起:

     public class LoadAppBilling extends AsyncTask <Result, Result, ArrayList<Boolean>> {

        static final String SKU_PREMIUMV = "test.hsdbgjfasbdfughvakcshfgb";
        static final String SKU_NO_ADDS = "test.blah";
        static final String TAG = "Azores Bus Premium";
        IabHelper mHelper;
        boolean mPremiumV = false;
        boolean mAdds = false;

        IabHelper.QueryInventoryFinishedListener mGotInventoryListener
                = new IabHelper.QueryInventoryFinishedListener() {
            public void onQueryInventoryFinished(IabResult result,
                                                 Inventory inventory) {

                if (result.isFailure()) {
                    Log.d(TAG, "didnt load");
                    return;
                }
                Log.d(TAG, " load");

                if (inventory.hasPurchase(SKU_PREMIUMV)) {
                             mPremiumV = true;
                    return;
                }
                if (inventory.hasPurchase(SKU_NO_ADDS)) {
                             mAdds = true;
                }

            }
        };

        @Override
        public ArrayList<Boolean> doInBackground(Result... params) {

            String base64EncodedPublicKey = "";

            Log.d(TAG, "Creating IAB helper.");
            mHelper = new IabHelper(getApplication(), base64EncodedPublicKey);

            mHelper.enableDebugLogging(true);

            mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
                public void onIabSetupFinished(IabResult result) {
                    if (!result.isSuccess()) {
                        // Oh noes, there was a problem.
                        Log.d(TAG, "Problem setting up In-app Billing: " + result);
                    }
                    // Hooray, IAB is fully set up!
                    mHelper.queryInventoryAsync(mGotInventoryListener);
                }
            });

            ArrayList<Boolean> retVal = new ArrayList<Boolean>();
            retVal.add(mPremiumV);
            retVal.add(mAdds);

            return retVal;
        }

    @Override
    public void onPostExecute(ArrayList<Boolean>  result) {

    }

}

片段代码:

new LoadAppBilling() {
         @Override
     public void onPostExecute (ArrayList<Boolean> result) {
     super.onPostExecute(result);

     //This will auto-unbox to boolean primitive
     boolean mPremiumV = result.get(0);
     boolean mAdds = result.get(1);


if (mPremiumV) {
//open a fragment 

} else {    
// show a dialog
    }}
}
.execute();
break;
 类似资料:
  • 问题内容: 因此,我试图从根本上建立一个用户选择ID的网页,然后该网页将ID信息发送给python,在python中,python使用该ID来查询数据库,然后将结果返回给该网页进行显示。 我不太确定该怎么做。我知道如何使用ajax调用来调用python生成的数据,但是我不确定如何将初始id信息传达给django应用。是否可以说,查询../app/id(IE / app / 8)之类的网址,然后使用

  • 问题内容: 我正在为我的学校创建一个应用程序,该应用程序应每n分钟检查一次网站上是否有新标记。为此,当用户首次登录时,实际标记的编号将保存在“ UserDefaults”中。当应用终止时,n分钟后,将重新计算标记的数量,并将其与前一个标记进行比较,并在更改数量时发送通知。 我想知道是否有一种方法可以执行此任务。我尝试在-applicationWillTerminate-中创建一个计时器,但只触发了

  • 我正在开发一个应用程序,它通过Firebase消息传递获取数据,将其插入SQLite并在应用程序中显示信息(如果它是可见的) 这是我的SQLIte帮助器类中的相关调用 偶尔我会得到这个错误,通常是在同时收到多个消息时: “Exception java.lang.IllegalStateException:无法执行此操作,因为连接池已关闭。”

  • 问题内容: 运行XCT UI测试时,可以使用以下命令将应用程序置于后台进行测试: 是否可以通过某种方式使应用程序回到前台(活动状态)而无需重新启动应用程序? 问题答案: Xcode 9更新 :从 Xcode 9 开始,您现在可以简单地调用任何XCUIApplication。 https://developer.apple.com/documentation/xctest/xcuiapplicati

  • 使用FCM,当应用程序在后台或未运行时,我会在系统托盘中接收推送通知。当应用程序处于前台时,我可以覆盖onMessageReceived并使用创建自己的提示通知。 谢谢 编辑:这里是我通过curl使用的消息负载,以供参考

  • 守护态运行 Detached 当我们启动一个container时,首先需要确定这个container是运行在前台模式还是运行在后台模式。 如果在docker run 后面追加-d=true或者-d,则containter将会运行在后台模式(Detached mode)。此时所有I/O数据只能通过网络资源或者共享卷组来进行交互。因为container不再监听你执行docker run的这个终端命令行