chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
01/30/13 10:09 AM (12 years ago)

Question about Java classes and Buzztouch

So I'm trying to get caught up on Android so I can port over the plugin's I have in review. I came across a decent 20,000 foot overview of Java for people already familiar with coding: http://mobile.tutsplus.com/tutorials/android/java-tutorial/ However, I noticed something interesting in lesson 7 (that's as far as I've gotten right now, and I'm only mid-way through the lesson at that - so I could be completely wrong in my thinking). But it talks about declaring a static nested class that can be accessed from outside the parent class without instatiating the parent class. If I'm thinking about this correctly, wouldn't it be better to make the class for handling screendata (i.e., public class DownloadScreenDataWorker extends Thread) as a public static class? That way, plugins could simply call the class rather than duplicating the code. I'm sure I'm overlooking something, so please educate me!
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
01/30/13 10:15 AM (12 years ago)
I love mobile.tutsplus.com. Sorry couldn't add to that
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/30/13 10:21 AM (12 years ago)
Hey @chris1, In Android, you call different classes to implement with the screen. For example, Myscreen.java is the coding for this screen, myscreen.xml. Each java has different activities in them that can be defined with buttons, imageview, textview and so on. Within each activity you call the button and what that button is going to do with a onClickListener for example. One way to call this is to extend a class or activity within the java class and this saves repeating different methods within the class. Make sense? LA
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/30/13 10:29 AM (12 years ago)
@LA - I think I follow what you're saying, but how does that relate to the DownloadScreenDataWorker class? Could you do something like this: someClass.DownloadScreenDataWorker downloadScreenDataWorker = new someclass.DownloadScreenDataWorker(); instead of: downloadScreenDataWorker = new DownloadScreenDataWorker(); And then have the DownloadScreenDataWorker be a public static class in the someClass java file? It seems like that would be a lot cleaner than declaring and implementing the DownloadScreenDataWorker class in every plugin when it uses the same code.
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/30/13 11:28 AM (12 years ago)
@chris1, You have to declare it as a variable first. Everything has to be declared as a variable first within the class or activity. So yes as long as you declare it as a variable then you can do that unless I am confused on what you are trying to do. Edit: Yes, I would extend the class and make it public. I'm not sure why they teach it that way. LA
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
01/30/13 12:21 PM (12 years ago)
@Chris: Not too much time to chat about this but would love a lengthy conversation about it at some point - I love this stuff. For sure there are a zillion ways implement all the logic involved this stuff. The way you describe (using a public static class) would likely work fine in a ton of situations. And, I agree that each Plugin would be a bit more cleaner this way. For sure in fact. There are two main reasons we went this this approach (which could change of course): 1) The data downloader class in plugins that use it is running in a separate thread (off the UI thread) so the interface doesn't block while the download is running. There are cases when static classes freak out when run in different threads. I'm sure there's a way around that issue but we haven't looked into them. 2) New developers / Learners: We've found that including much of the logic in the same file helps newcomers understand easier what's happening when their activity runs. This is also true for folks trying to understand how to make a new plugin. It just seems easier to not have to look at a bunch of files then make all the mental connections about how it's all working. Not sure how valid this is but for sure something we think about alot - is this understandable! LOL. I can think of a zillion things that could be totally re-thought, in term of how the Android projects are laid out. And, at some point we'll certainly need to make some big changes (as time goes on code tends to get dated). Who knows what those changes will be. Scary! Neat to see you taking an interest in this nerdy stuff. Feel free to experiment, make that static class you're referring to, see if it works well. We can always include something new in a project if it makes sense. d.
 
LA
Aspiring developer
Profile
Posts: 3280
Reg: Aug 16, 2012
Jerseyville, IL
42,900
like
01/30/13 12:25 PM (12 years ago)
Thank you David @buzztouch. I knew I was over my head after I tried to answer it..lol LA
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/30/13 12:44 PM (12 years ago)
Thanks David - that's helpful. Glad to know I wasn't off track in my thinking. Maybe I can get a handle on the Jaba side after all :)
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
01/30/13 02:50 PM (12 years ago)
Bravo on Point #2, David! Reading through code is a lot easier when I'm not whisked off to a function/procedure in another file every few lines. Cheers! -- Smug
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/30/13 02:53 PM (12 years ago)
I actually find the opposite to be the case, but I understand I'm not always the norm! For me, it's easier to see the big picture when I see summarized code, and can then drill down as necessary/wanted to learn more about a particular class/function.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.