0

Well, I'm at a dilemma here. I made my own class that uses the Bluetooth class from android but I'm not sure where to put it. Extending the android Bluetooth class seems like a good idea but I need to override the onActivityResult() which is only available to an activity class. So, where would I put my class so that I have access to onActivityResult() (keeping in mind the idea here is to use as few dependencies as possible)?

In other words, I want to move the Bluetooth code from the main activity to a separate class.

2 Answers 2

0

You should to use separate file for each class. You can create a folder "engine". For example: com.mycorp.myapp.engine. You can get access to onActivityResult() very simple. For example: MainActivity.onActivityResult(). Note: function should be public. Or you can pass your activity to your CustomBluetooth's constructor.

public class CustomBluetooth {

    private Activity mActivity;

    /* Constructor */
    public CustomBluetooth (Activity pActivity ) {
        super();
        this.mActivity = pActivity;
    }

    /* Your functions */
    public int getResult() {
        return this.mActivity.onActivityResult();
    }
}

Alex. P.S. Sorry for my English:)

1
  • Ah, cool, I already did something similar but I didn't know you could call the onActivityResult() like that. :) Aug 14, 2013 at 15:27
0

Add an interface to your Bluetooth class and implement the interface in your activity.

1
  • You mean the other way around? Aug 14, 2013 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.