gpt4 book ai didi

java - 启动另一个 Activity 时是什么迫使android Activity 被破坏

转载 作者:行者123 更新时间:2023-11-30 01:01:14 25 4
gpt4 key购买 nike

我正在尝试添加应用内购买,当我调用
OpenIabHelper::launchPurchaseFlow 函数时:

  • 我看到 Google Play 购买窗口
  • onStoponDestroy 在我的主 Activity 中执行,没有调用 onActivityResult

所以最后我带着 GooglePlay 窗口和死掉的应用程序离开了

我尝试通过 startActivityForResult 启动另一个 Activity,它运行良好
(没有任何东西被破坏并且 onActivityResult 被调用),所以问题似乎出在 OpenIAB library

因此我的问题是:
什么可能会在调用 OpenIabHelper::launchPurchaseFlow 后强制销毁我的 Activity ?

它似乎不是系统,因为它有足够的内存,正如我所说
startActivityForResult 工作正常。
也没有异常(exception)被镇压所以我很困惑

如有任何帮助,我们将不胜感激

MyActivity.java

public class MyActivity extends AppCompatActivity {
private OpenIabHelper m_helper;
private Boolean m_bOpenIabInitialized = false;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

OpenIabHelper.Options.Builder builder = new OpenIabHelper.Options.Builder()
.addAvailableStores(new GooglePlay(this,null))
.addPreferredStoreName(OpenIabHelper.NAME_GOOGLE)
.setStoreSearchStrategy(OpenIabHelper.Options.SEARCH_STRATEGY_INSTALLER_THEN_BEST_FIT)
.setVerifyMode(OpenIabHelper.Options.VERIFY_SKIP)
.setCheckInventory(false);
m_helper = new OpenIabHelper(this, builder.build());
m_helper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
m_bOpenIabInitialized = result.isSuccess();
}
});
}


public void onListViewItemClicked(String sku, String payload) {
if (m_bOpenIabInitialized == null || !m_bOpenIabInitialized) return;
m_helper.launchPurchaseFlow(this, sku, 10001, null, payload);
}

@Override
public void startActivityForResult(Intent intent, int RequestCode) {
// never reaches here
Log.d(TAG, "startActivityForResult()");
}

@Override
protected void onActivityResult(int RequestCode, int ResultCode, Intent data) {
// never reaches here
Log.d(TAG, "onActivityResult()");
}
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example" >

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="com.android.vending.BILLING" />

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

最佳答案

您是否尝试过更改 Activity 的启动模式?也许 singleTop 启动模式会保留您的 Activity :

<activity
android:name=".MyActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

您可以在此处找到有关启动模式的更多信息: https://developer.android.com/guide/topics/manifest/activity-element.html#lmode

关于java - 启动另一个 Activity 时是什么迫使android Activity 被破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39366735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com