Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force subclasses to set a inner class in java

I'm developing an app that requires the use of Bluetooth. The issue is that I have several activities that use the Bluetooth communication and I'm creating a class that makes the communication. For that, I need to resend the result to the activity. I'm trying to implement the activity like this:

    public abstract class MyCommunicationActivity extends Activity {
    public static class MYHANDLER extends Handler{};
}

I want to to force every activity to create a HANDLER that handles the response from the communication class and this class will receive an object MyCommunication class so it knows that the activity will wave a subclass that is a handler to handle the result. I've did it like this, but my sub classes (those that extend MyCommunicationActivity) aren't being force to implement the handler.

How can I do this? Is it possible?

like image 361
Short Avatar asked Mar 21 '23 12:03

Short


1 Answers

Add a method like this:

public abstract Handler getHandler();

This will force all subclasses to implement getHandler() and return a Handler there.

like image 168
FD_ Avatar answered Apr 03 '23 19:04

FD_