我用app app(IAB)编写了一个应用程序。除了一件事,一切似乎都很好。如果我发起购买,则会出现Google Play IAB购买并且我购买了一件商品,然后会出现“购买完成”窗口,然后消失。但是,我的主应用程序似乎没有再次启动动画,几秒钟后,应用程序崩溃。我的logcat
输出表明它们是一个空指针异常(与我自己的编码有关 - 没有特定的Android)
try
{
Bundle buyIntentBundle = mService.getBuyIntent(3, mActivity.getPackageName(), (String)args[1], "inapp", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
if(buyIntentBundle.getInt("RESPONSE_CODE") == BILLING_RESPONSE_RESULT_OK)
{
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
try
{
mActivity.startIntentSenderForResult(pendingIntent.getIntentSender(),
1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0));
}
catch (SendIntentException e)
{
Log.v("MYINFO", "Error purchasing item.");
e.printStackTrace();
}
}
else
{
Log.v("MYINFO", "Error purchasing item.");
showResponse(buyIntentBundle.getInt("RESPONSE_CODE"));
}
}
catch (RemoteException e1)
{
e1.printStackTrace();
}
此代码位于我自己的AsyncTask采购类中,而mActivity是主要的Activity。代码
mActivity.startIntentSenderForResult(...)
在主Activity中调用'OnActivityResult(...)'然后发生崩溃。
任何想法我可能做错了什么?
谢谢。
我的logcat输出它:
V/MediaPlayer[Native](12951): start
E/MediaPlayer[Native](12951): start called in state 0
V/MediaPlayer[Native](12951): message received msg=100, ext1=-38, ext2=0
E/MediaPlayer[Native](12951): error (-38, 0)
D/MediaPlayer[Native](12951): calling notify_player_state: 0
V/MediaPlayer[Native](12951): callback application
V/MediaPlayer[Native](12951): back from callback
D/MediaPlayer[JAVA](12951): broadcasting MEDIA_CHANGE_PLAYER_STATE(with context) : 0x0
E/MediaPlayer[Native](12951): invoke failed: wrong state 0
D/MediaPlayer[JAVA](12951): broadcasting MEDIA_CHANGE_PLAYER_STATE(with context) : state = 0
V/MediaPlayer[Native](12951): MediaPlayer::setVolume(0.750000, 0.750000)
E/MediaPlayer[JAVA](12951): Error (-38,0)
V/MediaPlayerService( 301): [669] setVolume(0.750000, 0.750000)
V/AudioSink( 301): setVolume(0.750000, 0.750000)
W/dalvikvm(12951): threadid=33: thread exiting with uncaught exception (group=0x41b5ee48)
E/AndroidRuntime(12951): FATAL EXCEPTION: GLThread 22274
E/AndroidRuntime(12951): Process: com.mystuff.grame, PID: 12951
E/AndroidRuntime(12951): java.lang.NullPointerException
E/AndroidRuntime(12951): at com.mystuff.grame.core.SpriteBatch.add(SpriteBatch.java:50)
E/AndroidRuntime(12951): at com.mystuff.grame.core.Level.draw(Level.java:360)
E/AndroidRuntime(12951): at com.mystuff.grame.core.Grame.drawGame(Grame.java:245)
E/AndroidRuntime(12951): at com.mystuff.grame.core.Grame.onDrawFrame(Grame.java:178)
E/AndroidRuntime(12951): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
E/AndroidRuntime(12951): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
W/ActivityManager( 972): Force finishing activity com.mystuff.grame/.MainActivity
D/ActivityManager( 972): setFocusedStack: mFocusedStack=ActivityStack{439390b8 stackId=1, 21 tasks}
V/ActivityManager( 972): Moving to PAUSING: ActivityRecord{43d96740 u0 com.mystuff.grame/.MainActivity t421 f}
V/MediaPlayer[Native](12951): stop
E/MediaPlayer[Native](12951): stop called in state 0
V/MediaPlayer[Native](12951): message received msg=100, ext1=-38, ext2=0
E/MediaPlayer[Native](12951): error (-38, 0)
D/MediaPlayer[Native](12951): calling notify_player_state: 0
V/MediaPlayer[Native](12951): callback application
V/MediaPlayer[Native](12951): back from callback
V/ActivityManager( 972): Moving to PAUSED: ActivityRecord{43d96740 u0 com.mystuff.grame/.MainActivity t421 f} (pause complete)
V/ActivityManager( 972): Moving to STOPPING: ActivityRecord{43d96740 u0 com.mystuff.grame/.MainActivity t421 f} (finish requested)
I/ActivityManager( 972): resumeTopActivitiesLocked(): target Stack:ActivityStack{439390b8 stackId=1, 21 tasks}
D/ActivityManager( 972): resumeTopActivityLocked: Launching home next
V/ActivityManager( 972): moveHomeStack:
答案 0 :(得分:1)
你可能是对的。打开IAP对话框时,我认为触发了onPause。如果onPause被触发,则意味着许多变量被设置为null并像MediaPlayer一样关闭。它必须与应用内购买有关,因为直到应用内购买完成才会发生...似乎应用内购买流程导致我的某些变量变为空。
另外,当IAP对话框出现时,MediaPlayer(我认为是原因)被设置为强制暂停。您可以尝试做的是在初始化购买流程时(或按下按钮触发它时)暂停MediaPLayer并在完成后重新初始化