Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: android compile time verification that intent extras were passed

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.

like image 402
ekatz Avatar asked Nov 05 '22 22:11

ekatz


1 Answers

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.

like image 124
mgv Avatar answered Nov 09 '22 05:11

mgv