凹凸API Android的崩溃凹凸、API、Android

2023-09-08 08:37:33 作者:我不做作、只有点疯。

我有一个巨大的问题,在Android上凹凸的API。我安装一切都像在这个例子中,我第一次开始包含凹凸$ C $我的活动C中,它的伟大工程,现在如果我回去,然后重新启动它,它只是由于崩溃致命的信号错误...它发生的权利我所说的凹凸API的配置后。

也许我需要不再打电话了吗?但是,没有什么可检查是否已配置与否。

 公共类BumpActivity延伸活动{
    私人IBumpAPI API;
    私人ProgressDialog mDialog;

    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.bump);
        mDialog = ProgressDialog.show(BumpActivity.this,preparing凸点,加载);
        bindService(新意图(IBumpAPI.class.getName()),连接,
                Context.BIND_AUTO_CREATE);

        IntentFilter的过滤器=新的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(接收机,过滤器);

    }

    @覆盖
    公共无效onConfigurationChanged(配置NEWCONFIG){
        super.onConfigurationChanged(NEWCONFIG);
    }

    @覆盖
    公共无效onBack pressed(){
        意图resultIntent =新意图();
        的setResult(Activity.RESULT_CANCELED,resultIntent);
        super.onBack pressed();
    }
    私人最终ServiceConnection连接=新ServiceConnection(){
        @覆盖
        公共无效onServiceConnected(组件名的className,粘合剂的IBinder){

            Log.i(BumpTest,onServiceConnected);
            API = IBumpAPI.Stub.asInterface(粘合剂);
            新的Thread(){
                公共无效的run(){
                    尝试 {
                        api.configure(9b17d663752843a1bfa4cc72d309339e
                                凹凸用户);
                    }赶上(RemoteException的E){
                        Log.w(BumpTest,E);
                    }

                }
            }。开始();
            Log.d(功能测试,服务连接);
        }

        @覆盖
        公共无效onServiceDisconnected(组件名的className){
            Log.d(功能测试,服务中断);
        }
    };

    私人最终BroadcastReceiver的接收器=新的BroadcastReceiver(){
        @覆盖
        公共无效的onReceive(上下文的背景下,意图意图){
            最后弦乐行动= intent.getAction();
            尝试 {
                如果(action.equals(BumpAPIIntents.DATA_RECEIVED)){
                    getUserDetailFromBump(新的字符串(
                            intent.getByteArrayExtra(数据)));
                }否则,如果(action.equals(BumpAPIIntents.MATCHED)){
                    长的channelID =意图
                            .getLongExtra(proposedChannelID,0);
                    Log.i(功能测试,
                            再配上:
                                    + api.userIDForChannelID(的channelID));
                    api.confirm(的channelID,真正的);
                    吐司面包= Toast.makeText(
                            getApplicationContext(),
                            再配上:
                                    + api.userIDForChannelID(的channelID)
                            Toast.LENGTH_SHORT);
                    toast.show();
                }否则,如果(action.equals(BumpAPIIntents.CHANNEL_CONFIRMED)){
                    长的channelID = intent.getLongExtra(的channelID,0);
                    api.send(的channelID,CurrentUserManager.getSharedManager()
                            。.getCurrentUser()getUserId()的toString()getBytes()构造)。;
                }否则,如果(action.equals(BumpAPIIntents.NOT_MATCHED)){
                    吐司面包= Toast.makeText(getApplicationContext()
                            不匹配,Toast.LENGTH_SHORT);
                    toast.show();
                }否则,如果(action.equals(BumpAPIIntents.CONNECTED)){
                    mDialog.dismiss();
                    api.enableBumping();
                }
            }赶上(RemoteException的E){
            }
        }
    };

    公共无效getUserDetailFromBump(字符串数据){
        Log.i(用户ID,数据);
        LoginRequest登录=新LoginRequest(getApplicationContext());
        Log.i(令牌,login.getArchivedToken());
        AsyncHttpClient restRequest =新AsyncHttpClient();
        PersistentCookieStore饼干=新PersistentCookieStore(getApplicationContext());
        restRequest.setCookieStore(饼干);
        RequestParams PARAMS =新RequestParams();
        params.put(的auth_token,login.getArchivedToken());
        params.put(USER_ID,数据);
        Log.i(请求,preparing);
        restRequest.get(Constantes.API_URL +用户/ show.json,PARAMS,新AsyncHtt presponseHandler(){
            公共无效的onSuccess(字符串响应){
                Log.i(效应初探,响应);
                尝试 {
                    用户的用户=新用户(新的JSONObject(响应));
                    Log.i(用户,user.toString());
                    //驱动程序
                    如果(CurrentUserManager.getSharedManager()。getCurrentUser()。的getType()== 1){
                        。CurrentRouteManager.getSharedManager()getCurrentRoute()addPassanger(用户)。
                        意图resultIntent =新的意图(BumpActivity.this,DriverActivity.class);
                        resultIntent.putExtra(PASSENGER_ADDED,真正的);
                        的setResult(1,resultIntent);
                        完();
                    }
                    其他{
                        意图P =新的意图(BumpActivity.this,RoutePassenger.class);
                        p.putExtra(驱动程序,用户);
                        startActivity(对);
                    }
                }赶上(JSONException E){
                    // TODO自动生成的catch块
                    e.printStackTrace();
                }
            }

            @覆盖
            公共无效onFailure(的Throwable E){
                Log.i(错误,e.toString());
            }

        });

    }

    公共无效的OnStart(){
        Log.i(BumpTest,ONSTART);
        super.onStart();
    }

    公共无效onRestart(){
        Log.i(BumpTest,onRestart);
        super.onRestart();
    }

    公共无效onResume(){
        Log.i(BumpTest,onResume);

        super.onResume();
    }

    公共无效的onPause(){
        Log.i(BumpTest,的onPause);
        尝试 {
            api.disableBumping();

        }赶上(RemoteException的E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }
        super.onPause();
    }

    公共无效的onStop(){
        Log.i(BumpTest,的onStop);
        尝试 {
            api.disableBumping();

        }赶上(RemoteException的E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }
        super.onStop();
    }

    公共无效的onDestroy(){
        Log.i(BumpTest,的onDestroy);
        尝试 {
            api.disableBumping();

        }赶上(RemoteException的E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }
        unbindService(连接);
        unregisterReceiver(接收机);
        super.onDestroy();
    }

}
 

解决方案

我终于前几天解决它。由于我不是一个JAVA专家,我认为这个bug位于凹凸库中。 如果你这样做api.configure时,它已经配置它只是崩溃。所以,我最终做一个单身,确保其只调用一次

下面是code

 公共类BumpConnection {

    保护上下文的背景下;
    私人IBumpAPI API;
    私有静态BumpConnection sharedManager;
    同步BumpConnection getSharedManager(上下文的背景下)公共静态{
        如果(sharedManager == NULL){
            sharedManager =新BumpConnection(上下文);
        }
        返回sharedManager;
    }

    私人BumpConnection(上下文的背景下){
        this.context =背景;
        context.bindService(新意图(IBumpAPI.class.getName()),连接,
                Context.BIND_AUTO_CREATE);
    }



    公共IBumpAPI getApi(){
        返回API;
    }

    公共无效setApi(IBumpAPI API){
        this.api = API;
    }



    私人最终ServiceConnection连接=新ServiceConnection(){
        @覆盖
        公共无效onServiceConnected(组件名的className,粘合剂的IBinder){

            Log.i(BumpTest,onServiceConnected);
            API = IBumpAPI.Stub.asInterface(粘合剂);
            新的Thread(){
                公共无效的run(){
                    尝试 {
                        api.configure(9b17d663752843a1bfa4cc72d309339e
                                凹凸用户);
                    }赶上(RemoteException的E){
                        Log.w(BumpTest,E);
                    }

                }
            }。开始();
            Log.d(功能测试,服务连接);
        }

        @覆盖
        公共无效onServiceDisconnected(组件名的className){
            Log.d(功能测试,服务中断);
        }
    };
}
 
谷歌发布Android 8.1首个开发者预览版 内存效率暴增

I have a huge problem with the bump API on Android. I setup everything like in the example, the first time I start my activity containing the bump code it works great, now if I go back and start it again it just crash due to a Fatal signal error... It happen right after I call the configure of the bump API.

May I need to not call it again ? But there is nothing to check if it already configured or not.

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();
    }

}

解决方案

I finally resolved it few days ago. As I'm not a JAVA expert I think the bug is located within the Bump library. If you do api.configure when it is already configured it simply crash. So I ended up making a singleton, ensuring that it is called only once

Here is the code

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");
        }
    };
} 

 
精彩推荐