1

使用 android 下载中提供的示例应用程序,我想在 onCreate() 方法中使用 api.disableBumping() 来添加广播接收器,但禁用碰撞,直至另行通知。应用程序不断在我身上崩溃。

任何指针?

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main);

    bindService(new Intent(IBumpAPI.class.getName()),
                connection, Context.BIND_AUTO_CREATE);

    IntentFilter filter = new IntentFilter();
    filter.addAction(BumpAPIIntents.CHANNEL_CONFIRMED);
    filter.addAction(BumpAPIIntents.DATA_RECEIVED);
    filter.addAction(BumpAPIIntents.NOT_MATCHED);
    filter.addAction(BumpAPIIntents.MATCHED);
    filter.addAction(BumpAPIIntents.CONNECTED);
    registerReceiver(receiver, filter);

    try {
        api.disableBumping();
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

调试信息

Thread [<1> main] (Suspended (exception RuntimeException))  
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1816    
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1837 
ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 132   
ActivityThread$H.handleMessage(Message) line: 1033  
ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 143 
ActivityThread.main(String[]) line: 4196    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 507  
ZygoteInit$MethodAndArgsCaller.run() line: 839  
ZygoteInit.main(String[]) line: 597 
NativeStart.main(String[]) line: not available [native method]
4

1 回答 1

0

在下面的几行中,我解释了 Bump 的逻辑是如何工作的,

打电话时

bindService(new Intent(IBumpAPI.class.getName()), connection, Context.BIND_AUTO_CREATE);   

onServiceConnected 被调用,然后你可以调用

    api = IBumpAPI.Stub.asInterface(binder);

    try  { api.configure("YOUR_API_KEY", "Bump User"); }
    catch (RemoteException e)  { } 

然后你等到收到广播CONNECTED,从那时起,何时调用 api.enableBumping() 或 api.disableBumping() 由你决定

注意:如果在调用 api.configure() 时连接断开,将引发远程异常。

于 2012-11-21T01:37:18.443 回答