I was wondering if anybody has ever created some sort of system that can check in compile time that intent extras are passed? I am passing extras with an intent to start another activity which tells the other activity how to behave
(for instance:
Intent i = new Intent(CurrentActivity.this, OtherActivity.class);
i.putExtra("ShowOverlay", false);
startActivity(i);
)
the problem is that I don't want future generations of developers to start this activity without sending this intent because there is no defined default behavior,
I assume that this is possible using some sort of annotation but might be difficult since tracking the intent object can be an impossible task at compile time. Just wondering if anybody ever thought of this and if this is theoretically possible.
I don't think there is any tool to accomplish what you want. Even if it did existed, you should program defensively.
If your activity needs some information to do its magic, just validate that you have received the correct information. Be informative on your error messages and provide a descriptive javadoc.
Moreover, perhaps you want that activity to respond to implicit intents and you should still be protected from malfunction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With