开发者

Android: android compile time verification that intent extras were passed

开发者 https://www.devze.com 2023-03-01 23:24 出处:网络
I was wondering if anybody has ever created some sort of system that can check in compile time that intent extras are 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 fu开发者_运维技巧ture 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消