Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Strangely enough, trying to google this question brings only this page as meaningful result... For the past half year I am using naming convention similar to yours but with shorter prefixes. For example: For activity that shows "About us" screen:</p> <p><strong>Class name</strong>: <code>ActAboutUs</code>. Prefixing class is kind of overkill but it clearly distinguishes activity classes from the others. Initially I used separate directory for all the activities (similar to your approach) but after some time I realized that for bigger apps may be it is better to group in directories by feature than by superclass (i.e. Activity). It is easier for me to work in single directory for example <code>/src/settings/</code> when I work on Settings. That way all java files that I need are in a single dir so i don't have to wander around:</p> <pre><code>/src/settings/ActSettingsGlobal.java /src/settings/ActSettingsNet.java /src/settings/Settings.java /src/settings/SettingsDBAdapter.java /src/settings/etc... </code></pre> <p>This approach also helps to split the work among different developers, i.e. each one is working in his own dir on separate feature so no stepping on each other's feet :-).</p> <p>Some people preffer suffixes but I found them less useful. Prefixes help to group things alphabetically like in the example above: <code>Act*</code> prefix is sorted first so all activities are conveniently at the top.</p> <p>I am even considering of using <code>Act_</code> as a prefix which is more readable although it is in conflict with java naming conventions...</p> <p><strong>Layout filename</strong>: <code>act_about_us.xml</code>. In <code>res/layout/</code> we don't have the "luxury" of subdirs which is quite unfortunate so the only way to group things is using appropriate prefix like <code>act_</code>, <code>dlg_</code>, etc... </p> <p><strong>String IDs</strong>: <code>&lt;string name="act_about_us_dlg_help1_title" ...</code> <code>string.xml</code> is the place where we have most problems with duplicate <code>name</code>s. It is very easy to create duplicates if naming convention like <code>activity_element_item</code> is not used. It adds a lot of additional typing but it saves you from a lot of confusion later on. For global (application wide) strings we use prefix <code>"global_"</code>, for example <code>global_btn_ok</code>, <code>global_msg_no_inet_conn</code>. Usually we make one person responsible for all <code>global_</code> strings so if someone needs new string or change he needs to sync with him in order to avoid creating a mess.</p> <p>(now I am realizing that <code>activity__element__item</code> (two underscores) is more clear and readable than <code>activity_element_item</code>)</p> <p>All in all I still can't get rid of the feeling that there is something wrong with my approach because I can't believe that google devs created such an inconvenient framework when it comes to working with files, IDs, names, etc...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload