2016-09-07 70 views
1

我嘗試添加應用內購買時被銷燬,當我打電話
OpenIabHelper::launchPurchaseFlow功能:
什麼力量機器人活動啓動另一個活動

  • 我看到谷歌播放購買窗口
  • onStoponDestroy在我的主要活動,而不調用那麼,到底執行onActivityResult

我留下GOOGLEPLAY窗口和我的死應用

我試圖通過startActivityForResult啓動另一個活動,它工作得很好
(沒有被破壞,onActivityResult叫),如此看來這個問題是OpenIAB library

因此,我的問題是:
什麼可能會迫使我的活動在致電OpenIabHelper::launchPurchaseFlow後被銷燬?

它似乎不是系統,因爲它有足夠的內存,正如我所說
startActivityForResult工作正常。
也沒有例外是trown所以我很困惑

任何幫助,將不勝感激

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> 
+0

你不能在你的debug.apk –

+0

測試Live產品SKU如此,照顧它 –

+0

@VishalPatoliya很好的知道,但在釋放問題依然存在和谷歌商店活動工作正常 –

回答

1

你有沒有試過改變該活動的launchMode?也許singleTop啓動模式將保留您的活動:

<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

+0

我做了一些研究,跟隨你的launchMode建議,並得出結論,這是關閉我的活動的Android系統(我猜是因爲它機智(約20MB內存))。無論如何,謝謝你的幫助 –

相關問題