Bump API Android crash

 ̄綄美尐妖づ 提交于 2019-12-06 12:21:56

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

Use Latest bump api , available at git hub, read the README.md file carefully. There is clearly mentioned that by using .aidl file (that is available in src folder) first compile it by using command

android update project -t android-15 -l path_to/bump-api-library -p path_to_your_project/

in your terminal.. If you are a Linux user then set path up to platform-tools then use this command with ./adb .

Then refresh the project , set this Library project as library in your test bump project.. Also replace your bumpapi key that you received via email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!