Java 安卓崩溃

Java 安卓崩溃,java,android,crash,bump,Java,Android,Crash,Bump,我对Android上的bump API有一个很大的问题。我像示例中一样设置了所有内容,第一次启动包含凹凸代码的活动时效果很好,现在如果我返回并再次启动它,它会由于致命的信号错误而崩溃。。。它发生在我调用bumpapi的configure之后 我可以不用再打电话吗?但是没有什么可以检查它是否已经配置好了 public class BumpActivity extends Activity { private IBumpAPI api; private ProgressDialog

我对Android上的bump API有一个很大的问题。我像示例中一样设置了所有内容,第一次启动包含凹凸代码的活动时效果很好,现在如果我返回并再次启动它,它会由于致命的信号错误而崩溃。。。它发生在我调用bumpapi的configure之后

我可以不用再打电话吗?但是没有什么可以检查它是否已经配置好了

public class BumpActivity extends Activity {
    private IBumpAPI api;
    private ProgressDialog mDialog;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bump);
        mDialog = ProgressDialog.show(BumpActivity.this, "Preparing bump", "Loading");
        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);

    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }

    @Override 
    public void onBackPressed(){
        Intent resultIntent = new Intent();
        setResult(Activity.RESULT_CANCELED, resultIntent);
        super.onBackPressed(); 
    }
    private final ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName className, IBinder binder) {

            Log.i("BumpTest", "onServiceConnected");
            api = IBumpAPI.Stub.asInterface(binder);
            new Thread() {
                public void run() {
                    try {
                        api.configure("9b17d663752843a1bfa4cc72d309339e",
                                "Bump User");
                    } catch (RemoteException e) {
                        Log.w("BumpTest", e);
                    }

                }
            }.start();
            Log.d("Bump Test", "Service connected");
        }

        @Override
        public void onServiceDisconnected(ComponentName className) {
            Log.d("Bump Test", "Service disconnected");
        }
    };

    private final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            try {
                if (action.equals(BumpAPIIntents.DATA_RECEIVED)) {
                    getUserDetailFromBump(new String(
                            intent.getByteArrayExtra("data")));
                } else if (action.equals(BumpAPIIntents.MATCHED)) {
                    long channelID = intent
                            .getLongExtra("proposedChannelID", 0);
                    Log.i("Bump Test",
                            "Matched with: "
                                    + api.userIDForChannelID(channelID));
                    api.confirm(channelID, true);
                    Toast toast = Toast.makeText(
                            getApplicationContext(),
                            "Matched with: "
                                    + api.userIDForChannelID(channelID),
                            Toast.LENGTH_SHORT);
                    toast.show();
                } else if (action.equals(BumpAPIIntents.CHANNEL_CONFIRMED)) {
                    long channelID = intent.getLongExtra("channelID", 0);
                    api.send(channelID, CurrentUserManager.getSharedManager()
                            .getCurrentUser().getUserId().toString().getBytes());
                } else if (action.equals(BumpAPIIntents.NOT_MATCHED)) {
                    Toast toast = Toast.makeText(getApplicationContext(),
                            "No match", Toast.LENGTH_SHORT);
                    toast.show();
                } else if (action.equals(BumpAPIIntents.CONNECTED)) {
                    mDialog.dismiss(); 
                    api.enableBumping();
                }
            } catch (RemoteException e) {
            }
        }
    };

    public void getUserDetailFromBump(String data) {
        Log.i("User Id", data); 
        LoginRequest login = new LoginRequest(getApplicationContext());
        Log.i("Token", login.getArchivedToken()); 
        AsyncHttpClient restRequest = new AsyncHttpClient();
        PersistentCookieStore cookie = new PersistentCookieStore(getApplicationContext()); 
        restRequest.setCookieStore(cookie); 
        RequestParams params = new RequestParams();
        params.put("auth_token", login.getArchivedToken()); 
        params.put("user_id", data); 
        Log.i("Request", "Preparing"); 
        restRequest.get(Constantes.API_URL + "users/show.json", params, new AsyncHttpResponseHandler(){
            public void onSuccess(String response) {
                Log.i("Reponse", response); 
                try {
                    User user = new User(new JSONObject(response));
                    Log.i("User", user.toString()); 
                    //Driver
                    if (CurrentUserManager.getSharedManager().getCurrentUser().getType() == 1){
                        CurrentRouteManager.getSharedManager().getCurrentRoute().addPassanger(user); 
                        Intent resultIntent = new Intent(BumpActivity.this, DriverActivity.class);
                        resultIntent.putExtra("PASSENGER_ADDED", true); 
                        setResult(1, resultIntent);
                        finish(); 
                    }
                    else{
                        Intent p = new Intent(BumpActivity.this, RoutePassenger.class); 
                        p.putExtra("driver", user); 
                        startActivity(p); 
                    }
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } 
            }

            @Override
            public void onFailure(Throwable e) {
                Log.i("Error", e.toString()); 
            }

        }); 

    }

    public void onStart() {
        Log.i("BumpTest", "onStart");
        super.onStart();
    }

    public void onRestart() {
        Log.i("BumpTest", "onRestart");
        super.onRestart();
    }

    public void onResume() {
        Log.i("BumpTest", "onResume");

        super.onResume();
    }

    public void onPause() {
        Log.i("BumpTest", "onPause");
        try {
            api.disableBumping();

        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        super.onPause();
    }

    public void onStop() {
        Log.i("BumpTest", "onStop");
        try {
            api.disableBumping();

        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        super.onStop();
    }

    public void onDestroy() {
        Log.i("BumpTest", "onDestroy");
        try {
            api.disableBumping();

        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        unbindService(connection);
        unregisterReceiver(receiver);
        super.onDestroy();
    }

}

几天前我终于解决了这个问题。因为我不是JAVA专家,所以我认为bug位于Bump库中。 如果在已经配置api.configure的情况下执行该操作,它将崩溃。所以我最终制作了一个单例,确保它只被调用一次

这是密码

public class BumpConnection {

    protected Context context; 
    private IBumpAPI api;
    private static BumpConnection sharedManager;
    public static synchronized BumpConnection getSharedManager(Context context) {
        if (sharedManager == null) {
            sharedManager = new BumpConnection(context);
        }
        return sharedManager;
    }

    private BumpConnection(Context context){
        this.context = context; 
        context.bindService(new Intent(IBumpAPI.class.getName()), connection,
                Context.BIND_AUTO_CREATE);
    }



    public IBumpAPI getApi() {
        return api;
    }

    public void setApi(IBumpAPI api) {
        this.api = api;
    }



    private final ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName className, IBinder binder) {

            Log.i("BumpTest", "onServiceConnected");
            api = IBumpAPI.Stub.asInterface(binder);
            new Thread() {
                public void run() {
                    try {
                        api.configure("9b17d663752843a1bfa4cc72d309339e",
                                "Bump User");
                    } catch (RemoteException e) {
                        Log.w("BumpTest", e);
                    }

                }
            }.start();
            Log.d("Bump Test", "Service connected");
        }

        @Override
        public void onServiceDisconnected(ComponentName className) {
            Log.d("Bump Test", "Service disconnected");
        }
    };
} 

使用git hub上提供的最新bump api,仔细阅读README.md文件。 这里清楚地提到,通过使用.aidl文件(在src文件夹中可用),首先使用命令编译它

android更新项目-t android-15-l路径到/通气api库-p路径到您的项目/

在你的终端。。 如果您是Linux用户,请设置平台工具的路径,然后将此命令与./adb一起使用

然后刷新项目,将此库项目设置为测试通气项目中的库。。
同时替换您通过电子邮件收到的bumpapi密钥

@Dimillian77 hii我正在制作这种类型的应用程序。从github获取api演示,但无法连接此应用程序。因此,您可以为bumpapi提供演示,以便我可以启动此应用程序。我希望实现与您相同的功能。请帮助我使用了您的解决方案,但它仍然无法为您服务我每当我断开WiFi连接时,致命信号将出现,在其他情况下,当触发bump事件时,匹配的事件将不会再次触发,直到我关闭并重新启动应用程序。您的问题和答案+1,因为我在第二次连接bump时面临相同的问题。那么,你能详细介绍一下你的工作吗demo@Dimillian77在这个问题上你能帮我吗。