What's proper technique for naming packages in an Android Application? - java

Specifically, what's the proper etiquette/conventions and terms for the different directories in Android Studio app folder?
Within that directory there are three more directories including java, but within Java are four layers of directories labelled com.test.cad.breadcrumbs, where breadcrumbs is the name of the application. Originally, test was set because I was just learning Android Studio, but now that it's actually an app, what should it be refactored to? Is it a package name? Can someone clarify terminology?
For example - why is the first directory called com? Or cad?
Image of File Structure

It's well explained at Oracle documentation:
Naming a Package

Thanks to #CommonsWare in the comments my question was answered.
Essentially, reverse domain name convention is used for the base of the package name. So if I'm "apple.com" then I use "com.apple". It must be likely to be unique at the moment and unlikely to have a collision in the future.
After this base, any java package name is up to you.

Related

How to use Scratch Files in Android Studio?

Recently I came across a cool feature in Android Studio called scratch files. Just wanted to share it in Q and A Style.
What are scratch files and how to use them?
It's a cool feature that lets you save your code that you want to look at later or just for reference.
See this post
Say you are creating a class and you decide to change a section of code. You can create a new scratch file by right clicking on the navigation bar and selection New, and then scratch file. Copy and save the code in the scratch file. This file is not a part of your android studio project.
You can find this file under scratches scope or Scratches folder under Scratches and Consoles folder in Project Scope.
Hope this will interest you guys and help speeding up development.
Sometimes you may need to create temporary notes or draft up some code outside of the project context. Instead of switching to a different application for this purpose, you can use scratch files and scratch buffers.
To create a scratch file, you can use ALT+CTRL+SHIFT+insert
or on OS X use Command+SHIFT+N
you can read more about it here: docs
It is the same metaphor as a "scratch book", a place to note down useful code fragments or ideas that can be useful to return to later on.

What should be my Android package name? [duplicate]

This question already has answers here:
Android - Package Name convention
(7 answers)
Closed 6 years ago.
I am new to Android development, and i don't know what should be my Android package name. My developer name is: "G.Games" and i don't have an own domain. Can i use this: com.g.games.appname ?
In general, a package name begins with the top level domain name of the organization and then the organization's domain and then any subdomains, listed in reverse order. The organization can then choose a specific name for its package. Subsequent components of the package name vary according to an organization's own internal naming conventions.
For example, if an organization in Canada called MySoft creates a package to deal with fractions, naming the package ca.mysoft.fractions distinguishes the fractions package from another similar package created by another company.
for instance, packages from Adobe would be of the form:
com.adobe.reader (Adobe Reader)
com.adobe.photoshop (Adobe Photoshop)
com.adobe.ideas (Adobe Ideas)
The concept comes from Package Naming Conventions in Java, more about which can be read here:
wikipedia
quora
You can use any name you want as long as it wont conflict with any other package name in the play store. There are huge number of applications in the store so if you use your own name chances are there may be some application with the same name. By using a domain name you can be sure that there are no other packages of the same name. For more details you can refer this link http://developer.android.com/guide/topics/manifest/manifest-element.html
Look under the package paragraph. Hope this helps you.

Unable to import image resources into our GUI

I'm working on a project with some friends over Github for a University project. I've only just taken my friends code off the repository for the first time. For some reason, all references to images in the code don't seem to allow compilation due to a directory problem I think. I'm using Eclipse, my friend's using Netbeans(don't know if that affects it or not?). Anyway, all of the images referenced are either in a folder known as runone, on the same level as the Eclipse src, or within the package 'runone' within src. I don't know which.
Here's an example of some of the references:
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/runone/OSTeeeennny.jpg")))
jLabel53.setIcon(new javax.swing.ImageIcon(getClass().getResource("/runone/clown_fishTIny.jpg")));
I guess what I'm wanting to know is, how can I make these resources work correctly, on any machine that we code this program on?
Hope that all made sense!
For the examples you have given your file structure might look like this
src/com/yourpackage/YourClass.java
src/runone/OSTeeeennny.jpg
src/runone/clown_fishTIny.jpg
For a more best practice way of organizing your resources you could do this
src/com/yourpackage/YourClass.java
src/com/yourpackage/resources/OSTeeeennny.jpg
src/com/yourpackage/resources/clown_fishTIny.jpg
and then use the following calls to load them
getClass().getResource("resources/OSTeeeennny.jpg")
getClass().getResource("resources/clown_fishTIny.jpg")

Android App Development in multiple languages

I am developing one Android application in three languages named English,Spanish and German.First I completed development in English and wish to complete it in other two languages. Here my question is:
Can I use the same code of Android project(which is in english) in the other two languages with different package names in the same project ?.
Please help me with the sample code/links.
of course you can. Follow these steps
make sure all of your strings through the application are listed as a resource in yourAppFolder/res/values/strings.xml and that you use strings in your app only via getString(R.string.myString1) and NEVER via hard-coded strings in your activities
create a new folder for each language you want to localize your app with the following syntax: for germany, values-de
copy the strings.xml file in the new folder you just created
translate each string in the file into your desired language
Now android OS will use the proper language based on the device's locale.
I bet that you don't fulfill requirement #1 and that will be the most of your work to do. At least that was happened to me in my first real android app ;)

Can I include code from one file to the next, similar to Includes in html

Ok, Please be gentle and kind. I am taking an Android Programming class in college and its our teachers first semester so he is learning as we are... Nothing against him, he's a good teacher, just doesn't know the answer.
I don't know how to put this in Android/java language so here goes...
Is there a way to use something similar to Includes, in web design, in Android. I am looking to add similar java code from one activity to the next, can i make a file that if i change this one file it will change in all the files its included it.
I know it can be done with the XML files but i couldn't find anything to show that it can be done in the actually coding... but then again i don't know the correct terminology. Please any help would be great. And thank you for taking the time to read and answer me. I apologize if this was somewhere else, I just couldn't find it.. Thanks again
Put anything you wish to "include" in Java classes, then import them. http://leepoint.net/notes-java/language/10basics/import.html
Android Programming class! I would've loved that in University...
Regardless, if you're using Eclipse for your IDE, it should pickup any changes from your java imports automatically. If you choose to refactor other java classes within your project, a rename for example (with "Update All References"), will update all references to that class across your project.
You could also use Maven (dependency management) to pull the latest third-party (or other) .jars at build time, if that's applicable to what your needs are.
:)

Categories

Resources